elseware-ui 2.33.0 → 2.34.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/dist/index.js CHANGED
@@ -188,6 +188,427 @@ function resolveAppearanceStyles({
188
188
  return solid[variant];
189
189
  }
190
190
  }
191
+
192
+ // src/utils/configurator/errors.ts
193
+ var ConfiguratorError = class extends Error {
194
+ constructor(message, cause) {
195
+ super(message);
196
+ this.name = "ConfiguratorError";
197
+ this.cause = cause;
198
+ }
199
+ };
200
+ function formatIssue(issue) {
201
+ const path = issue.path?.join(".") || "config";
202
+ return `${path} : ${issue.message ?? "Invalid value"}`;
203
+ }
204
+ function formatConfigError(error) {
205
+ const maybeZodError = error;
206
+ if (Array.isArray(maybeZodError.issues)) {
207
+ return maybeZodError.issues.map(formatIssue).join("\n");
208
+ }
209
+ if (maybeZodError?.message) {
210
+ return maybeZodError.message;
211
+ }
212
+ return "Invalid configuration";
213
+ }
214
+ function toConfiguratorError(error, fallbackMessage) {
215
+ if (error instanceof ConfiguratorError) {
216
+ return error;
217
+ }
218
+ if (error instanceof Error) {
219
+ return new ConfiguratorError(error.message || fallbackMessage, error);
220
+ }
221
+ return new ConfiguratorError(fallbackMessage, error);
222
+ }
223
+
224
+ // src/utils/configurator/Configurator.ts
225
+ var Configurator = class {
226
+ constructor(options) {
227
+ this.initialized = false;
228
+ this.config = null;
229
+ this.configError = null;
230
+ this.name = options.name ?? "config";
231
+ this.source = options.env;
232
+ this.schema = options.schema;
233
+ this.transform = options.transform;
234
+ if (options.validateOnCreate !== false) {
235
+ this.reload();
236
+ }
237
+ }
238
+ get isValid() {
239
+ this.ensureInitialized();
240
+ return !this.configError;
241
+ }
242
+ get error() {
243
+ this.ensureInitialized();
244
+ return this.configError;
245
+ }
246
+ get value() {
247
+ this.ensureInitialized();
248
+ if (this.configError) {
249
+ throw this.configError;
250
+ }
251
+ return this.config;
252
+ }
253
+ get optionalValue() {
254
+ this.ensureInitialized();
255
+ return this.config;
256
+ }
257
+ reload(env = this.source) {
258
+ this.source = env;
259
+ this.initialized = true;
260
+ const result = this.schema.safeParse(env);
261
+ if (!result.success) {
262
+ this.config = null;
263
+ this.configError = toConfiguratorError(
264
+ result.error,
265
+ formatConfigError(result.error)
266
+ );
267
+ return {
268
+ success: false,
269
+ config: null,
270
+ error: this.configError
271
+ };
272
+ }
273
+ try {
274
+ this.config = this.transform ? this.transform(result.data, { name: this.name }) : result.data;
275
+ this.configError = null;
276
+ return {
277
+ success: true,
278
+ config: this.config,
279
+ error: null
280
+ };
281
+ } catch (error) {
282
+ this.config = null;
283
+ this.configError = toConfiguratorError(
284
+ error,
285
+ `Failed to transform ${this.name}`
286
+ );
287
+ return {
288
+ success: false,
289
+ config: null,
290
+ error: this.configError
291
+ };
292
+ }
293
+ }
294
+ get(key) {
295
+ this.ensureInitialized();
296
+ if (!this.config) {
297
+ return void 0;
298
+ }
299
+ return this.config[key];
300
+ }
301
+ getRequired(key) {
302
+ const value = this.get(key);
303
+ if (value === void 0 || value === null) {
304
+ throw new Error(`Missing required config value: ${String(key)}`);
305
+ }
306
+ return value;
307
+ }
308
+ getPath(path, fallback) {
309
+ this.ensureInitialized();
310
+ if (!this.config) {
311
+ return fallback;
312
+ }
313
+ const value = path.split(".").reduce((current, key) => {
314
+ if (!current || typeof current !== "object") {
315
+ return void 0;
316
+ }
317
+ return current[key];
318
+ }, this.config);
319
+ return value === void 0 ? fallback : value;
320
+ }
321
+ getPathRequired(path) {
322
+ const value = this.getPath(path);
323
+ if (value === void 0 || value === null) {
324
+ throw new Error(`Missing required config value: ${path}`);
325
+ }
326
+ return value;
327
+ }
328
+ ensureInitialized() {
329
+ if (!this.initialized) {
330
+ this.reload();
331
+ }
332
+ }
333
+ };
334
+
335
+ // src/utils/configurator/createConfigurator.ts
336
+ function createConfigurator(options) {
337
+ return new Configurator(options);
338
+ }
339
+
340
+ // src/utils/configurator/helpers/browser.ts
341
+ function getBrowserOrigin() {
342
+ if (typeof window === "undefined") {
343
+ return "";
344
+ }
345
+ return window.location.origin;
346
+ }
347
+ function getBrowserHref() {
348
+ if (typeof window === "undefined") {
349
+ return "";
350
+ }
351
+ return window.location.href;
352
+ }
353
+ function getBrowserRedirectURL(options = {}) {
354
+ const {
355
+ queryParam = "redirect_uri",
356
+ fallbackPath = "/",
357
+ currentHref = getBrowserHref(),
358
+ referrerMode = "path"
359
+ } = options;
360
+ try {
361
+ if (currentHref) {
362
+ const currentURL = new URL(currentHref);
363
+ const redirectUri = currentURL.searchParams.get(queryParam);
364
+ if (redirectUri) {
365
+ return redirectUri;
366
+ }
367
+ }
368
+ if (typeof document !== "undefined" && document.referrer) {
369
+ const referrerURL = new URL(document.referrer);
370
+ if (referrerMode === "full") {
371
+ return referrerURL.toString();
372
+ }
373
+ return `${referrerURL.pathname}${referrerURL.search}${referrerURL.hash}`;
374
+ }
375
+ return fallbackPath;
376
+ } catch {
377
+ return fallbackPath;
378
+ }
379
+ }
380
+
381
+ // src/utils/configurator/helpers/json.ts
382
+ function isRecord(value) {
383
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
384
+ }
385
+ function parseJson(value, key = "JSON value") {
386
+ if (isRecord(value) || Array.isArray(value)) {
387
+ return value;
388
+ }
389
+ if (typeof value !== "string") {
390
+ throw new ConfiguratorError(`${key} must be a JSON string`);
391
+ }
392
+ try {
393
+ return JSON.parse(value);
394
+ } catch {
395
+ throw new ConfiguratorError(`Invalid ${key} JSON`);
396
+ }
397
+ }
398
+ function parseJsonRecord(value, key = "JSON record", validateValue) {
399
+ const parsed = parseJson(value, key);
400
+ if (!isRecord(parsed)) {
401
+ throw new ConfiguratorError(`${key} must be a JSON object`);
402
+ }
403
+ return Object.entries(parsed).reduce(
404
+ (acc, [name, item]) => {
405
+ acc[name] = validateValue ? validateValue(name, item) : item;
406
+ return acc;
407
+ },
408
+ {}
409
+ );
410
+ }
411
+
412
+ // src/utils/configurator/helpers/url.ts
413
+ function assertAbsoluteURL(value, key = "URL") {
414
+ if (typeof value !== "string") {
415
+ throw new ConfiguratorError(`${key} must be a string URL`);
416
+ }
417
+ try {
418
+ const url = new URL(value);
419
+ if (!["http:", "https:"].includes(url.protocol)) {
420
+ throw new Error();
421
+ }
422
+ return url.toString();
423
+ } catch {
424
+ throw new ConfiguratorError(`${key} must be a valid http/https URL`);
425
+ }
426
+ }
427
+ function parseUrlMap(value, key = "URL map") {
428
+ return parseJsonRecord(
429
+ value,
430
+ key,
431
+ (name, item) => assertAbsoluteURL(item, `${key}.${name}`)
432
+ );
433
+ }
434
+ function buildURL(base, path = "", params = {}) {
435
+ const url = new URL(assertAbsoluteURL(base, "base URL"));
436
+ if (path) {
437
+ const currentPath = url.pathname.replace(/\/$/, "");
438
+ const nextPath = path.replace(/^\/+/, "");
439
+ url.pathname = `${currentPath}/${nextPath}`;
440
+ }
441
+ Object.entries(params).forEach(([key, value]) => {
442
+ if (value !== void 0 && value !== null) {
443
+ url.searchParams.set(key, String(value));
444
+ }
445
+ });
446
+ return url.toString();
447
+ }
448
+ function resolveURLMap(source) {
449
+ return typeof source === "function" ? source() : source;
450
+ }
451
+ function createURLResolver(source, options = {}) {
452
+ const { label = "URL" } = options;
453
+ return (tag, path = "", params = {}) => {
454
+ const map = resolveURLMap(source) ?? {};
455
+ const base = map[tag];
456
+ if (!base) {
457
+ throw new ConfiguratorError(`${label} not configured for tag: ${tag}`);
458
+ }
459
+ return buildURL(base, path, params);
460
+ };
461
+ }
462
+ function getAllowedOrigins(options = {}) {
463
+ const {
464
+ urls = [],
465
+ maps = [],
466
+ includeCurrentOrigin = true,
467
+ currentOrigin = getBrowserOrigin()
468
+ } = options;
469
+ const origins = /* @__PURE__ */ new Set();
470
+ if (includeCurrentOrigin && currentOrigin) {
471
+ origins.add(currentOrigin);
472
+ }
473
+ urls.forEach((url) => {
474
+ origins.add(new URL(assertAbsoluteURL(url)).origin);
475
+ });
476
+ maps.forEach((map) => {
477
+ Object.values(map ?? {}).forEach((url) => {
478
+ origins.add(new URL(assertAbsoluteURL(url)).origin);
479
+ });
480
+ });
481
+ return Array.from(origins);
482
+ }
483
+ function getSafeRedirect(options = {}) {
484
+ const {
485
+ redirectUri,
486
+ fallback = "/",
487
+ allowedOrigins = [],
488
+ currentOrigin = getBrowserOrigin(),
489
+ allowedProtocols = ["http:", "https:"]
490
+ } = options;
491
+ try {
492
+ if (!redirectUri) {
493
+ return fallback;
494
+ }
495
+ const url = new URL(redirectUri, currentOrigin || fallback);
496
+ if (!allowedProtocols.includes(url.protocol)) {
497
+ return fallback;
498
+ }
499
+ const allowed = new Set(allowedOrigins);
500
+ if (currentOrigin) {
501
+ allowed.add(currentOrigin);
502
+ }
503
+ if (!allowed.has(url.origin)) {
504
+ return fallback;
505
+ }
506
+ return url.toString();
507
+ } catch {
508
+ return fallback;
509
+ }
510
+ }
511
+ function getErrorMessage(error) {
512
+ if (!error) {
513
+ return "Unknown configuration error";
514
+ }
515
+ if (error instanceof Error) {
516
+ return error.message || "Unknown configuration error";
517
+ }
518
+ if (typeof error === "string") {
519
+ return error;
520
+ }
521
+ try {
522
+ return JSON.stringify(error, null, 2);
523
+ } catch {
524
+ return "Unknown configuration error";
525
+ }
526
+ }
527
+ function getErrorStack(error) {
528
+ if (error instanceof Error) {
529
+ return error.stack;
530
+ }
531
+ return null;
532
+ }
533
+ function EnvErrorScreen({
534
+ error,
535
+ title = "Invalid Environment Configuration",
536
+ description = "The app could not start because one or more environment values are missing or invalid.",
537
+ footer,
538
+ showStack = false
539
+ }) {
540
+ const message = getErrorMessage(error);
541
+ const stack = getErrorStack(error);
542
+ const lines = message.split("\n").filter(Boolean);
543
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "min-h-screen flex items-center justify-center bg-black text-white p-8", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "max-w-4xl w-full rounded-xl border border-red-500 bg-red-950/30 p-6 shadow-2xl shadow-red-950/40", children: [
544
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-5", children: [
545
+ /* @__PURE__ */ jsxRuntime.jsx("h1", { className: "text-2xl font-bold text-red-400 mb-2", children: title }),
546
+ description && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-red-100/80", children: description })
547
+ ] }),
548
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rounded-lg border border-red-500/30 bg-black/40 p-4", children: /* @__PURE__ */ jsxRuntime.jsx("pre", { className: "overflow-auto text-sm whitespace-pre-wrap text-red-100", children: lines.length > 0 ? lines.join("\n") : "Unknown configuration error" }) }),
549
+ showStack && stack && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mt-4 rounded-lg border border-red-500/20 bg-black/30 p-4", children: [
550
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mb-2 text-xs font-semibold uppercase tracking-wide text-red-300", children: "Stack trace" }),
551
+ /* @__PURE__ */ jsxRuntime.jsx("pre", { className: "overflow-auto text-xs whitespace-pre-wrap text-red-100/70", children: stack })
552
+ ] }),
553
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-5 text-sm text-red-100/70", children: footer ?? /* @__PURE__ */ jsxRuntime.jsxs("p", { children: [
554
+ "Fix your ",
555
+ /* @__PURE__ */ jsxRuntime.jsx("code", { className: "text-red-200", children: ".env" }),
556
+ " values and restart the development server."
557
+ ] }) })
558
+ ] }) });
559
+ }
560
+ var EnvErrorScreen_default = EnvErrorScreen;
561
+ function ConfigBootstrap({
562
+ config,
563
+ loadApp,
564
+ ErrorComponent = EnvErrorScreen_default,
565
+ LoadingComponent,
566
+ loadingFallback = null,
567
+ showStack = false
568
+ }) {
569
+ const [RootApp, setRootApp] = React3.useState(null);
570
+ const [loadError, setLoadError] = React3.useState(null);
571
+ React3.useEffect(() => {
572
+ if (!config.isValid) {
573
+ return;
574
+ }
575
+ let mounted = true;
576
+ loadApp().then((module) => {
577
+ if (mounted) {
578
+ setRootApp(() => module.default);
579
+ }
580
+ }).catch((error) => {
581
+ if (mounted) {
582
+ setLoadError(error);
583
+ }
584
+ });
585
+ return () => {
586
+ mounted = false;
587
+ };
588
+ }, [config, loadApp]);
589
+ if (!config.isValid) {
590
+ return /* @__PURE__ */ jsxRuntime.jsx(ErrorComponent, { error: config.error, showStack });
591
+ }
592
+ if (loadError) {
593
+ return /* @__PURE__ */ jsxRuntime.jsx(
594
+ ErrorComponent,
595
+ {
596
+ error: loadError,
597
+ title: "Application Startup Error",
598
+ description: "The app configuration was valid, but the application failed while loading.",
599
+ showStack
600
+ }
601
+ );
602
+ }
603
+ if (!RootApp) {
604
+ if (LoadingComponent) {
605
+ return /* @__PURE__ */ jsxRuntime.jsx(LoadingComponent, {});
606
+ }
607
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: loadingFallback });
608
+ }
609
+ return /* @__PURE__ */ jsxRuntime.jsx(RootApp, {});
610
+ }
611
+ var ConfigBootstrap_default = ConfigBootstrap;
191
612
  var EUIContext = React3.createContext(null);
192
613
  var EUIProvider = ({
193
614
  config,
@@ -5300,7 +5721,7 @@ var ShapeSwitch = () => {
5300
5721
  {
5301
5722
  value: currentShape,
5302
5723
  onChange: handleChange,
5303
- className: "\n px-3 py-2 rounded-md border border-gray-300\n bg-white dark:bg-gray-800\n text-sm shadow-sm\n focus:outline-none\n ",
5724
+ className: "\r\n px-3 py-2 rounded-md border border-gray-300\r\n bg-white dark:bg-gray-800\r\n text-sm shadow-sm\r\n focus:outline-none\r\n ",
5304
5725
  children: Object.keys(Shape).map((shape) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: shape, children: shape }, shape))
5305
5726
  }
5306
5727
  ) });
@@ -18294,7 +18715,7 @@ function MarkdownTOC({ title = "Table of Contents" }) {
18294
18715
  /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(
18295
18716
  "h2",
18296
18717
  {
18297
- className: "\n text-sm\n font-semibold\n uppercase\n tracking-wide\n text-gray-900\n dark:text-gray-100\n ",
18718
+ className: "\r\n text-sm\r\n font-semibold\r\n uppercase\r\n tracking-wide\r\n text-gray-900\r\n dark:text-gray-100\r\n ",
18298
18719
  children: title
18299
18720
  }
18300
18721
  ) }),
@@ -19624,7 +20045,7 @@ var GlowWrapper = ({
19624
20045
  /* @__PURE__ */ jsxRuntime.jsx(
19625
20046
  "span",
19626
20047
  {
19627
- className: "\n pointer-events-none absolute inset-0 opacity-0 \n group-hover:opacity-100 transition-opacity duration-300\n ",
20048
+ className: "\r\n pointer-events-none absolute inset-0 opacity-0 \r\n group-hover:opacity-100 transition-opacity duration-300\r\n ",
19628
20049
  style: { background: "var(--glow-bg)" }
19629
20050
  }
19630
20051
  ),
@@ -21326,6 +21747,9 @@ exports.CloudinaryProvider = CloudinaryProvider;
21326
21747
  exports.CloudinaryVideo = CloudinaryVideo_default;
21327
21748
  exports.Code = Code;
21328
21749
  exports.CommentThread = CommentThread_default;
21750
+ exports.ConfigBootstrap = ConfigBootstrap_default;
21751
+ exports.Configurator = Configurator;
21752
+ exports.ConfiguratorError = ConfiguratorError;
21329
21753
  exports.Content = Content;
21330
21754
  exports.ContentArea = ContentArea_default;
21331
21755
  exports.DEFAULT_GRAPH_THEME = DEFAULT_GRAPH_THEME;
@@ -21339,6 +21763,7 @@ exports.Drawer = Drawer;
21339
21763
  exports.DrawerToggler = DrawerToggler_default;
21340
21764
  exports.EUIDevLayout = EUIDevLayout_default;
21341
21765
  exports.EUIProvider = EUIProvider;
21766
+ exports.EnvErrorScreen = EnvErrorScreen_default;
21342
21767
  exports.Flag = Flag;
21343
21768
  exports.Flex = Flex;
21344
21769
  exports.FlexCol = FlexCol_default;
@@ -21479,15 +21904,25 @@ exports.WorldMapCountryTable = WorldMapCountryTable;
21479
21904
  exports.YoutubeVideoPlayer = YoutubeVideo_default;
21480
21905
  exports.addReplyToCache = addReplyToCache;
21481
21906
  exports.applyReactionState = applyReactionState;
21907
+ exports.assertAbsoluteURL = assertAbsoluteURL;
21908
+ exports.buildURL = buildURL;
21482
21909
  exports.cn = cn;
21910
+ exports.createConfigurator = createConfigurator;
21483
21911
  exports.createInitialGraphState = createInitialGraphState;
21912
+ exports.createURLResolver = createURLResolver;
21484
21913
  exports.decrementReplyCount = decrementReplyCount;
21485
21914
  exports.enumValues = enumValues;
21486
21915
  exports.formatCommentDate = formatCommentDate;
21916
+ exports.formatConfigError = formatConfigError;
21487
21917
  exports.formatGraphValue = formatGraphValue;
21918
+ exports.getAllowedOrigins = getAllowedOrigins;
21919
+ exports.getBrowserHref = getBrowserHref;
21920
+ exports.getBrowserOrigin = getBrowserOrigin;
21921
+ exports.getBrowserRedirectURL = getBrowserRedirectURL;
21488
21922
  exports.getCurrencySymbol = getCurrencySymbol;
21489
21923
  exports.getOptimisticDislikeState = getOptimisticDislikeState;
21490
21924
  exports.getOptimisticLikeState = getOptimisticLikeState;
21925
+ exports.getSafeRedirect = getSafeRedirect;
21491
21926
  exports.graphReducer = graphReducer;
21492
21927
  exports.incrementReplyCount = incrementReplyCount;
21493
21928
  exports.isMatch = isMatch;
@@ -21496,6 +21931,9 @@ exports.limitRealtimePoints = limitRealtimePoints;
21496
21931
  exports.normalize = normalize;
21497
21932
  exports.normalizeGraphData = normalizeGraphData;
21498
21933
  exports.normalizeGraphDataPoint = normalizeGraphDataPoint;
21934
+ exports.parseJson = parseJson;
21935
+ exports.parseJsonRecord = parseJsonRecord;
21936
+ exports.parseUrlMap = parseUrlMap;
21499
21937
  exports.removeComment = removeComment;
21500
21938
  exports.removeCommentTreeFromCache = removeCommentTreeFromCache;
21501
21939
  exports.replaceRealtimePoints = replaceRealtimePoints;
@@ -21504,6 +21942,7 @@ exports.resolveGraphColor = resolveGraphColor;
21504
21942
  exports.resolveGraphColors = resolveGraphColors;
21505
21943
  exports.resolveWithGlobal = resolveWithGlobal;
21506
21944
  exports.sendToast = sendToast;
21945
+ exports.toConfiguratorError = toConfiguratorError;
21507
21946
  exports.updateComment = updateComment;
21508
21947
  exports.updateReplyCacheComment = updateReplyCacheComment;
21509
21948
  exports.useClickOutside = useClickOutside;