@thatopen/components 2.4.0-alpha.30 → 2.4.0-alpha.32

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.
@@ -1,4 +1,4 @@
1
- import { ControlsSchema, ControlEntry } from "../../Types";
1
+ import { ControlsSchema } from "../../Types";
2
2
  import { Components } from "../../Components";
3
3
  export declare abstract class Configurator<T = any, U extends ControlsSchema = ControlsSchema> {
4
4
  protected abstract _config: U;
@@ -8,7 +8,6 @@ export declare abstract class Configurator<T = any, U extends ControlsSchema = C
8
8
  get controls(): U;
9
9
  constructor(component: T, components: Components, name: string, uuid?: string);
10
10
  set(data: Partial<U>): void;
11
- export(): any;
12
- import(serializedData: any): void;
13
- copyEntry(controlEntry: ControlEntry): ControlEntry;
11
+ export(controls?: ControlsSchema, exported?: any): any;
12
+ import(exported: any, imported?: any, first?: boolean): void;
14
13
  }
@@ -40,3 +40,8 @@ export type ControlEntry = BooleanSettingsControl | ColorSettingsControl | TextS
40
40
  export interface ControlsSchema {
41
41
  [name: string]: ControlEntry | ControlsSchema;
42
42
  }
43
+ export declare class ControlsUtils {
44
+ static isEntry(item: any): boolean;
45
+ static copySchema<T extends ControlsSchema = ControlsSchema>(schema: T, copy?: ControlsSchema): T;
46
+ static copyEntry(controlEntry: ControlEntry): ControlEntry;
47
+ }
package/dist/index.cjs CHANGED
@@ -3877,6 +3877,97 @@ class DataMap extends Map {
3877
3877
  }
3878
3878
  class ComponentWithUI extends Component {
3879
3879
  }
3880
+ class ControlsUtils {
3881
+ static isEntry(item) {
3882
+ const types = /* @__PURE__ */ new Set([
3883
+ "Boolean",
3884
+ "Color",
3885
+ "Text",
3886
+ "Number",
3887
+ "Select",
3888
+ "Vector3",
3889
+ "TextSet",
3890
+ "None"
3891
+ ]);
3892
+ return types.has(item.type);
3893
+ }
3894
+ static copySchema(schema, copy = {}) {
3895
+ for (const name in schema) {
3896
+ const entry = schema[name];
3897
+ if (this.isEntry(entry)) {
3898
+ copy[name] = this.copyEntry(entry);
3899
+ } else {
3900
+ copy[name] = {};
3901
+ this.copySchema(entry, copy[name]);
3902
+ }
3903
+ }
3904
+ return copy;
3905
+ }
3906
+ static copyEntry(controlEntry) {
3907
+ if (controlEntry.type === "Boolean") {
3908
+ const entry = controlEntry;
3909
+ return {
3910
+ type: entry.type,
3911
+ value: entry.value
3912
+ };
3913
+ }
3914
+ if (controlEntry.type === "Color") {
3915
+ const entry = controlEntry;
3916
+ return {
3917
+ type: entry.type,
3918
+ value: entry.value.clone()
3919
+ };
3920
+ }
3921
+ if (controlEntry.type === "Text") {
3922
+ const entry = controlEntry;
3923
+ return {
3924
+ type: entry.type,
3925
+ value: entry.value
3926
+ };
3927
+ }
3928
+ if (controlEntry.type === "Number") {
3929
+ const entry = controlEntry;
3930
+ return {
3931
+ type: entry.type,
3932
+ value: entry.value,
3933
+ min: entry.min,
3934
+ max: entry.max,
3935
+ interpolable: entry.interpolable
3936
+ };
3937
+ }
3938
+ if (controlEntry.type === "Select") {
3939
+ const entry = controlEntry;
3940
+ return {
3941
+ type: entry.type,
3942
+ value: entry.value,
3943
+ multiple: entry.multiple,
3944
+ options: new Set(entry.options)
3945
+ };
3946
+ }
3947
+ if (controlEntry.type === "Vector3") {
3948
+ const entry = controlEntry;
3949
+ return {
3950
+ type: entry.type,
3951
+ value: entry.value.clone()
3952
+ };
3953
+ }
3954
+ if (controlEntry.type === "TextSet") {
3955
+ const entry = controlEntry;
3956
+ return {
3957
+ type: entry.type,
3958
+ value: new Set(entry.value)
3959
+ };
3960
+ }
3961
+ if (controlEntry.type === "None") {
3962
+ const entry = controlEntry;
3963
+ return {
3964
+ type: entry.type,
3965
+ value: entry.value
3966
+ };
3967
+ }
3968
+ throw new Error("Invalid entry!");
3969
+ }
3970
+ }
3880
3971
  class EventManager {
3881
3972
  constructor() {
3882
3973
  /**
@@ -5552,12 +5643,7 @@ class Configurator {
5552
5643
  configManager.list.set(this.uuid, this);
5553
5644
  }
5554
5645
  get controls() {
5555
- const copy = {};
5556
- for (const name in this._config) {
5557
- const entry = this._config[name];
5558
- copy[name] = this.copyEntry(entry);
5559
- }
5560
- return copy;
5646
+ return ControlsUtils.copySchema(this._config);
5561
5647
  }
5562
5648
  set(data) {
5563
5649
  for (const name in data) {
@@ -5567,106 +5653,59 @@ class Configurator {
5567
5653
  }
5568
5654
  }
5569
5655
  }
5570
- export() {
5571
- const serializedData = {};
5572
- for (const id in this._config) {
5573
- const control = this._config[id];
5574
- if (control.type === "Color") {
5575
- const { r, g, b } = control.value;
5576
- serializedData[id] = { ...control, value: { r, g, b } };
5577
- } else if (control.type === "Vector3") {
5578
- const { x, y, z } = control.value;
5579
- serializedData[id] = { ...control, value: { x, y, z } };
5580
- } else if (control.type === "Select" || control.type === "TextSet") {
5581
- const value = Array.from(control.value);
5582
- serializedData[id] = { ...control, value };
5583
- } else {
5584
- serializedData[id] = { ...control };
5585
- }
5586
- }
5587
- return serializedData;
5588
- }
5589
- import(serializedData) {
5590
- const imported = {};
5591
- for (const id in serializedData) {
5592
- const control = serializedData[id];
5593
- if (control.type === "Color") {
5594
- const { r, g, b } = control.value;
5595
- imported[id] = { ...control, value: new THREE__namespace.Color(r, g, b) };
5596
- } else if (control.type === "Vector3") {
5597
- const { x, y, z } = control.value;
5598
- imported[id] = { ...control, value: new THREE__namespace.Vector3(x, y, z) };
5599
- } else if (control.type === "Select" || control.type === "TextSet") {
5600
- imported[id] = { ...control, value: new Set(control.value) };
5656
+ export(controls = this._config, exported = {}) {
5657
+ for (const id in controls) {
5658
+ const control = controls[id];
5659
+ const isControl = ControlsUtils.isEntry(control);
5660
+ if (isControl) {
5661
+ if (control.type === "Color") {
5662
+ const { r, g, b } = control.value;
5663
+ exported[id] = { ...control, value: { r, g, b } };
5664
+ } else if (control.type === "Vector3") {
5665
+ const { x, y, z } = control.value;
5666
+ exported[id] = { ...control, value: { x, y, z } };
5667
+ } else if (control.type === "TextSet") {
5668
+ const value = Array.from(control.value);
5669
+ exported[id] = { ...control, value };
5670
+ } else if (control.type === "Select") {
5671
+ const options = Array.from(control.options);
5672
+ exported[id] = { ...control, options };
5673
+ } else {
5674
+ exported[id] = { ...control };
5675
+ }
5601
5676
  } else {
5602
- imported[id] = { ...control };
5677
+ exported[id] = {};
5678
+ this.export(control, exported[id]);
5603
5679
  }
5604
5680
  }
5605
- this.set(imported);
5681
+ return exported;
5606
5682
  }
5607
- copyEntry(controlEntry) {
5608
- if (controlEntry.type === "Boolean") {
5609
- const entry = controlEntry;
5610
- return {
5611
- type: entry.type,
5612
- value: entry.value
5613
- };
5614
- }
5615
- if (controlEntry.type === "Color") {
5616
- const entry = controlEntry;
5617
- return {
5618
- type: entry.type,
5619
- value: entry.value.clone()
5620
- };
5621
- }
5622
- if (controlEntry.type === "Text") {
5623
- const entry = controlEntry;
5624
- return {
5625
- type: entry.type,
5626
- value: entry.value
5627
- };
5628
- }
5629
- if (controlEntry.type === "Number") {
5630
- const entry = controlEntry;
5631
- return {
5632
- type: entry.type,
5633
- value: entry.value,
5634
- min: entry.min,
5635
- max: entry.max,
5636
- interpolable: entry.interpolable
5637
- };
5638
- }
5639
- if (controlEntry.type === "Select") {
5640
- const entry = controlEntry;
5641
- return {
5642
- type: entry.type,
5643
- value: entry.value,
5644
- multiple: entry.multiple,
5645
- options: new Set(entry.options)
5646
- };
5647
- }
5648
- if (controlEntry.type === "Vector3") {
5649
- const entry = controlEntry;
5650
- return {
5651
- type: entry.type,
5652
- value: entry.value.clone()
5653
- };
5654
- }
5655
- if (controlEntry.type === "TextSet") {
5656
- const entry = controlEntry;
5657
- return {
5658
- type: entry.type,
5659
- value: new Set(entry.value)
5660
- };
5683
+ import(exported, imported = {}, first = true) {
5684
+ for (const id in exported) {
5685
+ const control = exported[id];
5686
+ const isControl = ControlsUtils.isEntry(control);
5687
+ if (isControl) {
5688
+ if (control.type === "Color") {
5689
+ const { r, g, b } = control.value;
5690
+ imported[id] = { ...control, value: new THREE__namespace.Color(r, g, b) };
5691
+ } else if (control.type === "Vector3") {
5692
+ const { x, y, z } = control.value;
5693
+ imported[id] = { ...control, value: new THREE__namespace.Vector3(x, y, z) };
5694
+ } else if (control.type === "TextSet") {
5695
+ imported[id] = { ...control, value: new Set(control.value) };
5696
+ } else if (control.type === "Select") {
5697
+ imported[id] = { ...control, options: new Set(control.options) };
5698
+ } else {
5699
+ imported[id] = { ...control };
5700
+ }
5701
+ } else {
5702
+ imported[id] = {};
5703
+ this.import(control, imported[id], false);
5704
+ }
5661
5705
  }
5662
- if (controlEntry.type === "None") {
5663
- const entry = controlEntry;
5664
- return {
5665
- type: entry.type,
5666
- value: entry.value
5667
- };
5706
+ if (first) {
5707
+ this.set(imported);
5668
5708
  }
5669
- throw new Error("Invalid entry!");
5670
5709
  }
5671
5710
  }
5672
5711
  const _ConfigManager = class _ConfigManager extends Component {
@@ -27650,6 +27689,7 @@ exports.ComponentWithUI = ComponentWithUI;
27650
27689
  exports.Components = Components;
27651
27690
  exports.ConfigManager = ConfigManager;
27652
27691
  exports.Configurator = Configurator;
27692
+ exports.ControlsUtils = ControlsUtils;
27653
27693
  exports.CullerRenderer = CullerRenderer;
27654
27694
  exports.Cullers = Cullers;
27655
27695
  exports.DataMap = DataMap;