dirk-cfx-react 1.1.73 → 1.1.75

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.
@@ -11,6 +11,7 @@ var clickSoundUrl = require('../click_sound-PNCRRTM4.mp3');
11
11
  var hoverSoundUrl = require('../hover_sound-NBUA222C.mp3');
12
12
  var notifications = require('@mantine/notifications');
13
13
  var reactQuery = require('@tanstack/react-query');
14
+ var colorsGenerator = require('@mantine/colors-generator');
14
15
 
15
16
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
16
17
 
@@ -3713,6 +3714,13 @@ function useForm() {
3713
3714
  }, [state.values, state.initialValues]);
3714
3715
  return { ...state, changedFields, changedCount: changedFields.length };
3715
3716
  }
3717
+ function useFormField(path) {
3718
+ const store = react.useContext(FormContext);
3719
+ if (!store) {
3720
+ throw new Error("useFormField must be used inside <FormProvider>");
3721
+ }
3722
+ return zustand.useStore(store, (s) => getNested(s.values, path));
3723
+ }
3716
3724
  function useFormActions() {
3717
3725
  const store = react.useContext(FormContext);
3718
3726
  if (!store) {
@@ -4099,7 +4107,22 @@ function ConfigPanelInner({
4099
4107
  if (result?.success) {
4100
4108
  const { store } = getScriptConfigInstance();
4101
4109
  form.reinitialize(cloneConfig(store.getState()));
4110
+ notifications.notifications.show({
4111
+ color: "green",
4112
+ title: locale("ConfigResetSuccessTitle"),
4113
+ message: locale("ConfigResetSuccessBody"),
4114
+ autoClose: 3e3
4115
+ });
4116
+ return;
4102
4117
  }
4118
+ const err = result?._error || "Unknown";
4119
+ console.warn(`[ConfigPanel] config reset failed: ${err}`);
4120
+ notifications.notifications.show({
4121
+ color: "red",
4122
+ title: locale("ConfigResetFailedTitle"),
4123
+ message: locale("ConfigResetFailedBody", err),
4124
+ autoClose: 6e3
4125
+ });
4103
4126
  },
4104
4127
  onClose: () => setResetOpen(false),
4105
4128
  zIndex: 300
@@ -5274,6 +5297,281 @@ function TestBed({
5274
5297
  }
5275
5298
  );
5276
5299
  }
5300
+ var MANTINE_COLOR_OPTIONS = [
5301
+ "dirk",
5302
+ "red",
5303
+ "pink",
5304
+ "grape",
5305
+ "violet",
5306
+ "indigo",
5307
+ "blue",
5308
+ "cyan",
5309
+ "teal",
5310
+ "green",
5311
+ "lime",
5312
+ "yellow",
5313
+ "orange"
5314
+ ].map((value) => ({ value, label: value }));
5315
+ var DEFAULT_PALETTE = [
5316
+ "#f0f4ff",
5317
+ "#d9e3ff",
5318
+ "#bfcfff",
5319
+ "#a6bbff",
5320
+ "#8ca7ff",
5321
+ "#7393ff",
5322
+ "#5a7fff",
5323
+ "#406bff",
5324
+ "#2547ff",
5325
+ "#0b33ff"
5326
+ ];
5327
+ var DEFAULT_VALUE = {
5328
+ useOverride: false,
5329
+ primaryColor: "dirk",
5330
+ primaryShade: 5,
5331
+ customTheme: DEFAULT_PALETTE
5332
+ };
5333
+ function GroupLabel({ label }) {
5334
+ return /* @__PURE__ */ jsxRuntime.jsxs(core.Flex, { align: "center", gap: "xs", mt: "xxs", children: [
5335
+ /* @__PURE__ */ jsxRuntime.jsx(core.Text, { ff: "Akrobat Bold", size: "xxs", tt: "uppercase", lts: "0.07em", c: "rgba(255,255,255,0.2)", children: label }),
5336
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: { flex: 1, height: "0.05vh", background: "rgba(255,255,255,0.06)" } })
5337
+ ] });
5338
+ }
5339
+ function ThemeOverrideSection({
5340
+ schemaKey = "theme",
5341
+ title
5342
+ }) {
5343
+ const mantineTheme = core.useMantineTheme();
5344
+ const color = mantineTheme.colors[mantineTheme.primaryColor][5];
5345
+ const raw = useFormField(schemaKey);
5346
+ const value = {
5347
+ useOverride: raw?.useOverride ?? DEFAULT_VALUE.useOverride,
5348
+ primaryColor: raw?.primaryColor ?? DEFAULT_VALUE.primaryColor,
5349
+ primaryShade: raw?.primaryShade ?? DEFAULT_VALUE.primaryShade,
5350
+ customTheme: Array.isArray(raw?.customTheme) && raw.customTheme.length === 10 ? raw.customTheme : DEFAULT_VALUE.customTheme
5351
+ };
5352
+ const { setValue } = useFormActions();
5353
+ const set = (key, val) => setValue(schemaKey, { ...value, [key]: val });
5354
+ const useCustom = value.primaryColor === "custom";
5355
+ const editable = value.useOverride;
5356
+ const setSwatch = (index, hex) => {
5357
+ const next = [...value.customTheme];
5358
+ next[index] = hex;
5359
+ set("customTheme", next);
5360
+ };
5361
+ const generateFromBase = (hex) => {
5362
+ try {
5363
+ const generated = colorsGenerator.generateColors(hex);
5364
+ set("customTheme", generated);
5365
+ } catch {
5366
+ }
5367
+ };
5368
+ const resetPalette = () => set("customTheme", DEFAULT_PALETTE);
5369
+ return /* @__PURE__ */ jsxRuntime.jsxs(
5370
+ core.Flex,
5371
+ {
5372
+ direction: "column",
5373
+ gap: "xs",
5374
+ p: "sm",
5375
+ style: { flex: 1, minHeight: 0, overflowY: "auto" },
5376
+ children: [
5377
+ /* @__PURE__ */ jsxRuntime.jsx(
5378
+ AdminPageTitle,
5379
+ {
5380
+ icon: lucideReact.Palette,
5381
+ title: title || locale("Theme") || "Theme",
5382
+ color
5383
+ }
5384
+ ),
5385
+ /* @__PURE__ */ jsxRuntime.jsxs(
5386
+ core.Flex,
5387
+ {
5388
+ align: "center",
5389
+ justify: "space-between",
5390
+ p: "xs",
5391
+ style: {
5392
+ background: `rgba(255,255,255,${editable ? 0.04 : 0.02})`,
5393
+ border: `0.1vh solid ${editable ? color : "rgba(255,255,255,0.08)"}`,
5394
+ borderRadius: mantineTheme.radius.xs,
5395
+ transition: "background 0.15s, border-color 0.15s"
5396
+ },
5397
+ children: [
5398
+ /* @__PURE__ */ jsxRuntime.jsxs(core.Flex, { direction: "column", gap: "xxs", style: { flex: 1, minWidth: 0 }, children: [
5399
+ /* @__PURE__ */ jsxRuntime.jsx(core.Text, { ff: "Akrobat Bold", size: "xs", c: "rgba(255,255,255,0.9)", children: locale("OverrideGlobalTheme") || "Override global theme" }),
5400
+ /* @__PURE__ */ jsxRuntime.jsx(core.Text, { ff: "Akrobat Bold", size: "xxs", c: "rgba(255,255,255,0.4)", children: locale("OverrideGlobalThemeDesc") || "When on, this resource uses its own primary colour and palette instead of dirk_lib's. Turn off to fall back to the global theme \u2014 your custom palette is kept." })
5401
+ ] }),
5402
+ /* @__PURE__ */ jsxRuntime.jsx(
5403
+ core.Switch,
5404
+ {
5405
+ size: "md",
5406
+ checked: value.useOverride,
5407
+ onChange: (e) => set("useOverride", e.currentTarget.checked)
5408
+ }
5409
+ )
5410
+ ]
5411
+ }
5412
+ ),
5413
+ /* @__PURE__ */ jsxRuntime.jsxs(
5414
+ "div",
5415
+ {
5416
+ style: {
5417
+ opacity: editable ? 1 : 0.4,
5418
+ pointerEvents: editable ? "auto" : "none",
5419
+ transition: "opacity 0.15s"
5420
+ },
5421
+ children: [
5422
+ /* @__PURE__ */ jsxRuntime.jsx(GroupLabel, { label: locale("PrimaryColor") || "Primary Colour" }),
5423
+ /* @__PURE__ */ jsxRuntime.jsx(
5424
+ core.Switch,
5425
+ {
5426
+ label: locale("UseCustomPalette") || "Use custom palette",
5427
+ size: "md",
5428
+ checked: useCustom,
5429
+ onChange: (e) => set("primaryColor", e.currentTarget.checked ? "custom" : "dirk"),
5430
+ styles: {
5431
+ label: {
5432
+ fontFamily: "Akrobat Bold",
5433
+ fontSize: "0.65em",
5434
+ letterSpacing: "0.06em",
5435
+ textTransform: "uppercase",
5436
+ color: "rgba(255,255,255,0.35)"
5437
+ }
5438
+ }
5439
+ }
5440
+ ),
5441
+ /* @__PURE__ */ jsxRuntime.jsxs(core.Flex, { gap: "xs", mt: "xs", children: [
5442
+ !useCustom && /* @__PURE__ */ jsxRuntime.jsx(
5443
+ core.Select,
5444
+ {
5445
+ label: locale("MantinePalette") || "Mantine palette",
5446
+ size: "xs",
5447
+ style: { flex: 1 },
5448
+ value: value.primaryColor,
5449
+ data: MANTINE_COLOR_OPTIONS,
5450
+ allowDeselect: false,
5451
+ onChange: (v) => v && set("primaryColor", v)
5452
+ }
5453
+ ),
5454
+ /* @__PURE__ */ jsxRuntime.jsx(
5455
+ core.NumberInput,
5456
+ {
5457
+ label: locale("Shade") || "Shade",
5458
+ size: "xs",
5459
+ style: { flex: 1 },
5460
+ min: 0,
5461
+ max: 9,
5462
+ value: value.primaryShade,
5463
+ onChange: (v) => set("primaryShade", Number(v))
5464
+ }
5465
+ )
5466
+ ] }),
5467
+ useCustom && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
5468
+ /* @__PURE__ */ jsxRuntime.jsxs(core.Flex, { align: "center", justify: "space-between", mt: "sm", children: [
5469
+ /* @__PURE__ */ jsxRuntime.jsx(
5470
+ core.Text,
5471
+ {
5472
+ ff: "Akrobat Bold",
5473
+ size: "xxs",
5474
+ tt: "uppercase",
5475
+ lts: "0.07em",
5476
+ c: "rgba(255,255,255,0.2)",
5477
+ children: locale("CustomPalette") || "Custom palette"
5478
+ }
5479
+ ),
5480
+ /* @__PURE__ */ jsxRuntime.jsx(
5481
+ core.ActionIcon,
5482
+ {
5483
+ size: "sm",
5484
+ variant: "subtle",
5485
+ onClick: resetPalette,
5486
+ title: locale("ResetPalette") || "Reset palette",
5487
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.RotateCcw, { size: "1.4vh" })
5488
+ }
5489
+ )
5490
+ ] }),
5491
+ /* @__PURE__ */ jsxRuntime.jsx(
5492
+ core.ColorInput,
5493
+ {
5494
+ label: locale("BaseColor") || "Base colour",
5495
+ size: "xs",
5496
+ value: value.customTheme[value.primaryShade] ?? value.customTheme[5] ?? "#000000",
5497
+ onChange: generateFromBase,
5498
+ eyeDropperIcon: /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, {})
5499
+ }
5500
+ ),
5501
+ /* @__PURE__ */ jsxRuntime.jsx(core.Flex, { gap: "xxs", mt: "xxs", children: value.customTheme.map((swatch, i) => /* @__PURE__ */ jsxRuntime.jsx(
5502
+ SwatchTile,
5503
+ {
5504
+ index: i,
5505
+ value: swatch,
5506
+ isPrimary: i === value.primaryShade,
5507
+ onChange: (v) => setSwatch(i, v)
5508
+ },
5509
+ i
5510
+ )) })
5511
+ ] })
5512
+ ]
5513
+ }
5514
+ )
5515
+ ]
5516
+ }
5517
+ );
5518
+ }
5519
+ function SwatchTile({
5520
+ index,
5521
+ value,
5522
+ isPrimary,
5523
+ onChange
5524
+ }) {
5525
+ const [opened, setOpened] = react.useState(false);
5526
+ return /* @__PURE__ */ jsxRuntime.jsxs(core.Popover, { opened, onChange: setOpened, position: "bottom", withArrow: true, zIndex: 1e4, children: [
5527
+ /* @__PURE__ */ jsxRuntime.jsx(core.Popover.Target, { children: /* @__PURE__ */ jsxRuntime.jsx(
5528
+ "button",
5529
+ {
5530
+ onClick: () => setOpened((o) => !o),
5531
+ title: `${index} \xB7 ${value}`,
5532
+ style: {
5533
+ flex: 1,
5534
+ aspectRatio: "1 / 1",
5535
+ background: value,
5536
+ border: isPrimary ? "0.2vh solid rgba(255,255,255,0.85)" : "0.1vh solid rgba(255,255,255,0.15)",
5537
+ borderRadius: "0.4vh",
5538
+ cursor: "pointer",
5539
+ padding: 0,
5540
+ display: "flex",
5541
+ alignItems: "flex-end",
5542
+ justifyContent: "flex-end",
5543
+ position: "relative"
5544
+ },
5545
+ children: /* @__PURE__ */ jsxRuntime.jsx(
5546
+ "span",
5547
+ {
5548
+ style: {
5549
+ fontFamily: "Akrobat Bold",
5550
+ fontSize: "0.9vh",
5551
+ lineHeight: 1,
5552
+ padding: "0.2vh 0.3vh",
5553
+ color: "rgba(0,0,0,0.55)",
5554
+ background: "rgba(255,255,255,0.55)",
5555
+ borderRadius: "0.25vh",
5556
+ margin: "0.2vh"
5557
+ },
5558
+ children: index
5559
+ }
5560
+ )
5561
+ }
5562
+ ) }),
5563
+ /* @__PURE__ */ jsxRuntime.jsx(core.Popover.Dropdown, { p: "xs", children: /* @__PURE__ */ jsxRuntime.jsx(
5564
+ core.ColorInput,
5565
+ {
5566
+ size: "xs",
5567
+ value,
5568
+ onChange,
5569
+ format: "hex",
5570
+ eyeDropperIcon: /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, {})
5571
+ }
5572
+ ) })
5573
+ ] });
5574
+ }
5277
5575
 
5278
5576
  exports.AdminPageTitle = AdminPageTitle;
5279
5577
  exports.AsyncSaveButton = AsyncSaveButton;
@@ -5312,6 +5610,7 @@ exports.SegmentedControl = SegmentedControl;
5312
5610
  exports.SegmentedProgress = SegmentedProgress;
5313
5611
  exports.SelectItem = SelectItem;
5314
5612
  exports.TestBed = TestBed;
5613
+ exports.ThemeOverrideSection = ThemeOverrideSection;
5315
5614
  exports.Title = Title;
5316
5615
  exports.Vector4DeleteButton = Vector4DeleteButton;
5317
5616
  exports.Vector4Display = Vector4Display;