@tangle-network/sandbox-ui 0.10.6 → 0.10.7

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.
Files changed (2) hide show
  1. package/dist/pages.js +54 -16
  2. package/package.json +1 -1
package/dist/pages.js CHANGED
@@ -411,6 +411,35 @@ var RAM_MIN = 2;
411
411
  var RAM_MAX = 32;
412
412
  var STORAGE_MIN = 20;
413
413
  var STORAGE_MAX = 512;
414
+ var CPU_STEP = 0.5;
415
+ var RAM_STEP = 1;
416
+ var STORAGE_STEP = 8;
417
+ function alignSliderStep(min, max, desiredStep) {
418
+ const range = max - min;
419
+ if (range <= 0 || desiredStep <= 0) return desiredStep;
420
+ if (Number.isInteger(desiredStep)) {
421
+ if (!Number.isInteger(range)) return desiredStep;
422
+ for (let c = Math.floor(desiredStep); c >= 1; c--) {
423
+ if (range % c === 0) return c;
424
+ }
425
+ return desiredStep;
426
+ }
427
+ const scale = 10;
428
+ const scaledRange = Math.round(range * scale);
429
+ const scaledStep = Math.round(desiredStep * scale);
430
+ for (let c = scaledStep; c >= 1; c--) {
431
+ if (scaledRange % c === 0) return c / scale;
432
+ }
433
+ return desiredStep;
434
+ }
435
+ function snapSliderValue(value, min, max, step) {
436
+ if (!Number.isFinite(value)) return min;
437
+ const clamped = Math.max(min, Math.min(value, max));
438
+ if (step <= 0) return clamped;
439
+ const steps = Math.round((clamped - min) / step);
440
+ const snapped = min + steps * step;
441
+ return Math.max(min, Math.min(snapped, max));
442
+ }
414
443
  var DEFAULT_PRICING_RATES = {
415
444
  cpuPerHr: 0.045,
416
445
  ramPerGbHr: 5e-3,
@@ -469,6 +498,9 @@ function ProvisioningWizard({
469
498
  STORAGE_MIN,
470
499
  Math.min(resourceLimits?.storageMaxGB ?? STORAGE_MAX, STORAGE_MAX)
471
500
  );
501
+ const cpuStep = alignSliderStep(CPU_MIN, cpuMax, CPU_STEP);
502
+ const ramStep = alignSliderStep(RAM_MIN, ramMax, RAM_STEP);
503
+ const storageStep = alignSliderStep(STORAGE_MIN, storageMax, STORAGE_STEP);
472
504
  const dc = defaultConfig;
473
505
  const [envList, setEnvList] = React2.useState(
474
506
  environmentsProp ?? defaultEnvironments
@@ -504,17 +536,21 @@ function ProvisioningWizard({
504
536
  }
505
537
  }, [envList, effectiveDefault]);
506
538
  const [cpuCores, setCpuCores] = React2.useState(
507
- Math.min(dc?.cpuCores ?? 4, cpuMax)
539
+ snapSliderValue(dc?.cpuCores ?? 4, CPU_MIN, cpuMax, cpuStep)
540
+ );
541
+ const [ramGB, setRamGB] = React2.useState(
542
+ snapSliderValue(dc?.ramGB ?? 16, RAM_MIN, ramMax, ramStep)
508
543
  );
509
- const [ramGB, setRamGB] = React2.useState(Math.min(dc?.ramGB ?? 16, ramMax));
510
544
  const [storageGB, setStorageGB] = React2.useState(
511
- Math.min(dc?.storageGB ?? 128, storageMax)
545
+ snapSliderValue(dc?.storageGB ?? 128, STORAGE_MIN, storageMax, storageStep)
512
546
  );
513
547
  React2.useEffect(() => {
514
- setCpuCores((prev) => Math.min(prev, cpuMax));
515
- setRamGB((prev) => Math.min(prev, ramMax));
516
- setStorageGB((prev) => Math.min(prev, storageMax));
517
- }, [cpuMax, ramMax, storageMax]);
548
+ setCpuCores((prev) => snapSliderValue(prev, CPU_MIN, cpuMax, cpuStep));
549
+ setRamGB((prev) => snapSliderValue(prev, RAM_MIN, ramMax, ramStep));
550
+ setStorageGB(
551
+ (prev) => snapSliderValue(prev, STORAGE_MIN, storageMax, storageStep)
552
+ );
553
+ }, [cpuMax, ramMax, storageMax, cpuStep, ramStep, storageStep]);
518
554
  const [modelTier, setModelTier] = React2.useState(
519
555
  dc?.modelTier ?? DEFAULT_MODEL_TIER
520
556
  );
@@ -600,9 +636,9 @@ function ProvisioningWizard({
600
636
  }
601
637
  };
602
638
  const applyPreset = (name2, cpu, ram, storage) => {
603
- setCpuCores(Math.min(cpu, cpuMax));
604
- setRamGB(Math.min(ram, ramMax));
605
- setStorageGB(Math.min(storage, storageMax));
639
+ setCpuCores(snapSliderValue(cpu, CPU_MIN, cpuMax, cpuStep));
640
+ setRamGB(snapSliderValue(ram, RAM_MIN, ramMax, ramStep));
641
+ setStorageGB(snapSliderValue(storage, STORAGE_MIN, storageMax, storageStep));
606
642
  setActivePreset(name2);
607
643
  };
608
644
  const presets = RAW_PRESETS.map((p) => {
@@ -726,9 +762,11 @@ function ProvisioningWizard({
726
762
  onClick: () => {
727
763
  setCurrentStep(1);
728
764
  setSelectedEnv(environments[0]?.id ?? "");
729
- setCpuCores(Math.min(4, cpuMax));
730
- setRamGB(Math.min(16, ramMax));
731
- setStorageGB(Math.min(128, storageMax));
765
+ setCpuCores(snapSliderValue(4, CPU_MIN, cpuMax, cpuStep));
766
+ setRamGB(snapSliderValue(16, RAM_MIN, ramMax, ramStep));
767
+ setStorageGB(
768
+ snapSliderValue(128, STORAGE_MIN, storageMax, storageStep)
769
+ );
732
770
  const resetOptions = modelOptions ?? DEFAULT_MODEL_OPTIONS;
733
771
  const firstAvailable = resetOptions.find(
734
772
  (o) => !o.disabled
@@ -845,7 +883,7 @@ function ProvisioningWizard({
845
883
  setter: setCpuCores,
846
884
  min: CPU_MIN,
847
885
  max: cpuMax,
848
- step: 0.5,
886
+ step: cpuStep,
849
887
  unit: "vCPU"
850
888
  },
851
889
  {
@@ -854,7 +892,7 @@ function ProvisioningWizard({
854
892
  setter: setRamGB,
855
893
  min: RAM_MIN,
856
894
  max: ramMax,
857
- step: 1,
895
+ step: ramStep,
858
896
  unit: "GB"
859
897
  },
860
898
  {
@@ -863,7 +901,7 @@ function ProvisioningWizard({
863
901
  setter: setStorageGB,
864
902
  min: STORAGE_MIN,
865
903
  max: storageMax,
866
- step: 8,
904
+ step: storageStep,
867
905
  unit: "GB"
868
906
  }
869
907
  ].map(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangle-network/sandbox-ui",
3
- "version": "0.10.6",
3
+ "version": "0.10.7",
4
4
  "description": "Unified UI component library for Tangle Sandbox — primitives, chat, dashboard, terminal, editor, and workspace components",
5
5
  "repository": {
6
6
  "type": "git",