@smilodon/react 1.12.0 → 1.12.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/README.md +15 -7
- package/dist/index.cjs +151 -239
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +151 -239
- package/dist/index.js.map +1 -1
- package/dist/types/Select.d.ts +6 -1
- package/dist/types/Select.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -17,6 +17,64 @@ function isPlainRecord(value) {
|
|
|
17
17
|
const prototype = Object.getPrototypeOf(value);
|
|
18
18
|
return prototype === Object.prototype || prototype === null;
|
|
19
19
|
}
|
|
20
|
+
function areSemanticallyEqual(left, right, seen = /* @__PURE__ */ new WeakMap()) {
|
|
21
|
+
var _a;
|
|
22
|
+
if (Object.is(left, right)) return true;
|
|
23
|
+
if (left === null || right === null || typeof left !== "object" || typeof right !== "object") {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
const leftArray = Array.isArray(left);
|
|
27
|
+
const rightArray = Array.isArray(right);
|
|
28
|
+
if (leftArray !== rightArray) return false;
|
|
29
|
+
if (!leftArray && (!isPlainRecord(left) || !isPlainRecord(right))) return false;
|
|
30
|
+
if (leftArray && !Array.isArray(right)) return false;
|
|
31
|
+
if (leftArray && rightArray && left.length !== right.length) return false;
|
|
32
|
+
const leftPrototype = Object.getPrototypeOf(left);
|
|
33
|
+
const rightPrototype = Object.getPrototypeOf(right);
|
|
34
|
+
if (leftPrototype !== rightPrototype && !(isPlainRecord(left) && isPlainRecord(right))) return false;
|
|
35
|
+
const prior = (_a = seen.get(left)) == null ? void 0 : _a.get(right);
|
|
36
|
+
if (prior !== void 0) return prior;
|
|
37
|
+
let rightPairs = seen.get(left);
|
|
38
|
+
if (!rightPairs) {
|
|
39
|
+
rightPairs = /* @__PURE__ */ new WeakMap();
|
|
40
|
+
seen.set(left, rightPairs);
|
|
41
|
+
}
|
|
42
|
+
rightPairs.set(right, true);
|
|
43
|
+
const enumerableKeys = (value) => Reflect.ownKeys(value).filter((key) => {
|
|
44
|
+
var _a2;
|
|
45
|
+
return (_a2 = Object.getOwnPropertyDescriptor(value, key)) == null ? void 0 : _a2.enumerable;
|
|
46
|
+
});
|
|
47
|
+
const leftKeys = enumerableKeys(left);
|
|
48
|
+
const rightKeys = enumerableKeys(right);
|
|
49
|
+
const rightKeySet = new Set(rightKeys);
|
|
50
|
+
if (leftKeys.length !== rightKeys.length) {
|
|
51
|
+
rightPairs.set(right, false);
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
for (const key of leftKeys) {
|
|
55
|
+
if (!rightKeySet.has(key)) {
|
|
56
|
+
rightPairs.set(right, false);
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
const leftDescriptor = Object.getOwnPropertyDescriptor(left, key);
|
|
60
|
+
const rightDescriptor = Object.getOwnPropertyDescriptor(right, key);
|
|
61
|
+
if ("value" in leftDescriptor !== "value" in rightDescriptor) {
|
|
62
|
+
rightPairs.set(right, false);
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
if ("value" in leftDescriptor) {
|
|
66
|
+
if (!areSemanticallyEqual(leftDescriptor.value, rightDescriptor.value, seen)) {
|
|
67
|
+
rightPairs.set(right, false);
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
} else if (leftDescriptor.get !== rightDescriptor.get || leftDescriptor.set !== rightDescriptor.set) {
|
|
71
|
+
rightPairs.set(right, false);
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
const EMPTY_ITEMS = [];
|
|
20
78
|
function isBusyToken(value) {
|
|
21
79
|
return value === true || value === "true";
|
|
22
80
|
}
|
|
@@ -28,7 +86,7 @@ function composeBusyToken(consumerValue, externalBusy) {
|
|
|
28
86
|
const Select = forwardRef((props, ref) => {
|
|
29
87
|
var _a, _b, _c;
|
|
30
88
|
const {
|
|
31
|
-
items =
|
|
89
|
+
items = EMPTY_ITEMS,
|
|
32
90
|
groupedItems,
|
|
33
91
|
value,
|
|
34
92
|
defaultValue,
|
|
@@ -615,156 +673,108 @@ const Select = forwardRef((props, ref) => {
|
|
|
615
673
|
return (_a2 = activeListenersRef.current) == null ? void 0 : _a2.dispose();
|
|
616
674
|
};
|
|
617
675
|
}, []);
|
|
618
|
-
|
|
619
|
-
var _a2;
|
|
620
|
-
const element = elementRef.current;
|
|
621
|
-
if (!element || !isElementUsable) return;
|
|
622
|
-
if (!element.setItems) {
|
|
623
|
-
console.warn("Enhanced select element not fully initialized yet");
|
|
624
|
-
return;
|
|
625
|
-
}
|
|
626
|
-
if (groupedItems) {
|
|
627
|
-
element.setGroupedItems(groupedItems);
|
|
628
|
-
} else if (items.length > 0) {
|
|
629
|
-
element.setItems(items);
|
|
630
|
-
}
|
|
631
|
-
const config = {
|
|
632
|
-
searchable,
|
|
633
|
-
placeholder,
|
|
634
|
-
virtualize: virtualized,
|
|
635
|
-
estimatedItemHeight,
|
|
636
|
-
enabled: !disabled,
|
|
637
|
-
dropdownPlacement: {
|
|
638
|
-
mode: resolvedDropdownPlacement
|
|
639
|
-
},
|
|
640
|
-
selection: {
|
|
641
|
-
...selectionConfig,
|
|
642
|
-
mode: multiple ? "multi" : "single",
|
|
643
|
-
maxSelections,
|
|
644
|
-
removeButtonIcon: typeof removeButtonIcon === "string" ? removeButtonIcon : void 0,
|
|
645
|
-
disabledOptionBehavior,
|
|
646
|
-
showSelectedIndicator,
|
|
647
|
-
toggleOnTriggerClick
|
|
648
|
-
},
|
|
649
|
-
direction,
|
|
650
|
-
multiSelectDisplay,
|
|
651
|
-
infiniteScroll: {
|
|
652
|
-
enabled: infiniteScroll,
|
|
653
|
-
pageSize
|
|
654
|
-
},
|
|
655
|
-
scrollToSelected: {
|
|
656
|
-
enabled: true,
|
|
657
|
-
...scrollToSelected
|
|
658
|
-
},
|
|
659
|
-
creatable,
|
|
660
|
-
styles: stylesConfig,
|
|
661
|
-
clearControl: {
|
|
662
|
-
enabled: clearable,
|
|
663
|
-
clearSelection: clearSelectionOnClear,
|
|
664
|
-
clearSearch: clearSearchOnClear,
|
|
665
|
-
ariaLabel: clearAriaLabel,
|
|
666
|
-
icon: clearIcon
|
|
667
|
-
},
|
|
668
|
-
tracking: {
|
|
669
|
-
enabled: trackingEnabled,
|
|
670
|
-
events: trackEvents,
|
|
671
|
-
styling: trackStyling,
|
|
672
|
-
limitations: trackLimitations,
|
|
673
|
-
emitDiagnostics,
|
|
674
|
-
maxEntries: trackingMaxEntries
|
|
675
|
-
},
|
|
676
|
-
limitations: {
|
|
677
|
-
policies: limitationPolicies,
|
|
678
|
-
autoMitigateRuntimeModeSwitch
|
|
679
|
-
}
|
|
680
|
-
};
|
|
681
|
-
applyInstanceConfig(element, config);
|
|
682
|
-
if (coreConfig) {
|
|
683
|
-
applyInstanceConfig(element, coreConfig);
|
|
684
|
-
}
|
|
685
|
-
if (!isControlled && !hasAppliedInitialValueRef.current && internalValue !== void 0) {
|
|
686
|
-
const values = Array.isArray(internalValue) ? internalValue : [internalValue];
|
|
687
|
-
const currentValues = ((_a2 = element.getSelectedValues) == null ? void 0 : _a2.call(element)) || [];
|
|
688
|
-
if (!areValuesEqual(values, currentValues)) {
|
|
689
|
-
element.setSelectedValues(values);
|
|
690
|
-
}
|
|
691
|
-
hasAppliedInitialValueRef.current = true;
|
|
692
|
-
}
|
|
693
|
-
if (error) {
|
|
694
|
-
element.setError(errorMessage || "Invalid selection");
|
|
695
|
-
} else {
|
|
696
|
-
element.clearError();
|
|
697
|
-
}
|
|
698
|
-
if (required) {
|
|
699
|
-
element.setRequired(true);
|
|
700
|
-
}
|
|
701
|
-
}, [
|
|
702
|
-
isElementUsable,
|
|
703
|
-
items,
|
|
704
|
-
groupedItems,
|
|
676
|
+
const componentConfig = {
|
|
705
677
|
searchable,
|
|
706
678
|
placeholder,
|
|
707
|
-
virtualized,
|
|
679
|
+
virtualize: virtualized,
|
|
708
680
|
estimatedItemHeight,
|
|
709
|
-
disabled,
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
681
|
+
enabled: !disabled,
|
|
682
|
+
dropdownPlacement: { mode: resolvedDropdownPlacement },
|
|
683
|
+
selection: {
|
|
684
|
+
...selectionConfig,
|
|
685
|
+
mode: multiple ? "multi" : "single",
|
|
686
|
+
maxSelections,
|
|
687
|
+
removeButtonIcon: typeof removeButtonIcon === "string" ? removeButtonIcon : void 0,
|
|
688
|
+
disabledOptionBehavior,
|
|
689
|
+
showSelectedIndicator,
|
|
690
|
+
toggleOnTriggerClick
|
|
691
|
+
},
|
|
692
|
+
direction,
|
|
713
693
|
multiSelectDisplay,
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
coreConfig,
|
|
717
|
-
removeButtonIcon,
|
|
718
|
-
disabledOptionBehavior,
|
|
719
|
-
showSelectedIndicator,
|
|
720
|
-
toggleOnTriggerClick,
|
|
721
|
-
infiniteScroll,
|
|
722
|
-
pageSize,
|
|
694
|
+
infiniteScroll: { enabled: infiniteScroll, pageSize },
|
|
695
|
+
scrollToSelected: { enabled: true, ...scrollToSelected },
|
|
723
696
|
creatable,
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
697
|
+
styles: stylesConfig,
|
|
698
|
+
clearControl: {
|
|
699
|
+
enabled: clearable,
|
|
700
|
+
clearSelection: clearSelectionOnClear,
|
|
701
|
+
clearSearch: clearSearchOnClear,
|
|
702
|
+
ariaLabel: clearAriaLabel,
|
|
703
|
+
icon: clearIcon
|
|
704
|
+
},
|
|
705
|
+
tracking: {
|
|
706
|
+
enabled: trackingEnabled,
|
|
707
|
+
events: trackEvents,
|
|
708
|
+
styling: trackStyling,
|
|
709
|
+
limitations: trackLimitations,
|
|
710
|
+
emitDiagnostics,
|
|
711
|
+
maxEntries: trackingMaxEntries
|
|
712
|
+
},
|
|
713
|
+
limitations: { policies: limitationPolicies, autoMitigateRuntimeModeSwitch }
|
|
714
|
+
};
|
|
715
|
+
const configCandidate = { component: componentConfig, core: coreConfig };
|
|
716
|
+
const appliedConfigRef = useRef({ hasComponent: false, component: null, hasCore: false, core: void 0 });
|
|
717
|
+
useEffect(() => {
|
|
718
|
+
const element = elementRef.current;
|
|
719
|
+
if (!element || !isElementUsable || !element.updateConfig) return;
|
|
720
|
+
const previous = appliedConfigRef.current;
|
|
721
|
+
const componentChanged = !previous.hasComponent || !areSemanticallyEqual(previous.component, configCandidate.component);
|
|
722
|
+
const coreChanged = !previous.hasCore || !areSemanticallyEqual(previous.core, configCandidate.core);
|
|
723
|
+
if (!componentChanged && !coreChanged) return;
|
|
724
|
+
if (componentChanged) {
|
|
725
|
+
applyInstanceConfig(element, configCandidate.component);
|
|
726
|
+
if (configCandidate.core) applyInstanceConfig(element, configCandidate.core);
|
|
727
|
+
} else if (coreChanged) {
|
|
728
|
+
if (configCandidate.core) {
|
|
729
|
+
applyInstanceConfig(element, configCandidate.core);
|
|
730
|
+
} else {
|
|
731
|
+
applyInstanceConfig(element, configCandidate.component);
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
appliedConfigRef.current = {
|
|
735
|
+
hasComponent: true,
|
|
736
|
+
component: configCandidate.component,
|
|
737
|
+
hasCore: true,
|
|
738
|
+
core: configCandidate.core
|
|
739
|
+
};
|
|
740
|
+
});
|
|
741
|
+
const sourceCandidate = groupedItems !== void 0 ? { kind: "grouped", data: groupedItems } : { kind: "items", data: items };
|
|
742
|
+
const synchronizedSourceRef = useRef(null);
|
|
747
743
|
useEffect(() => {
|
|
744
|
+
var _a2;
|
|
748
745
|
const element = elementRef.current;
|
|
749
746
|
if (!element || !isElementUsable || !element.setItems) return;
|
|
750
|
-
if (
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
const map = /* @__PURE__ */ new Map();
|
|
754
|
-
items.forEach((it) => {
|
|
755
|
-
const g = it.group ?? "Ungrouped";
|
|
756
|
-
if (!map.has(g)) map.set(g, []);
|
|
757
|
-
map.get(g).push(it);
|
|
758
|
-
});
|
|
759
|
-
const groups = Array.from(map.entries()).map(([label, options]) => ({
|
|
760
|
-
label,
|
|
761
|
-
options
|
|
762
|
-
}));
|
|
763
|
-
element.setGroupedItems(groups);
|
|
747
|
+
if (areSemanticallyEqual(synchronizedSourceRef.current, sourceCandidate)) return;
|
|
748
|
+
if (sourceCandidate.kind === "grouped") {
|
|
749
|
+
element.setGroupedItems(sourceCandidate.data);
|
|
764
750
|
} else {
|
|
765
|
-
|
|
751
|
+
const sourceItems = sourceCandidate.data;
|
|
752
|
+
if (sourceItems.length > 0 && ((_a2 = sourceItems[0]) == null ? void 0 : _a2.group) !== void 0) {
|
|
753
|
+
const groups = /* @__PURE__ */ new Map();
|
|
754
|
+
sourceItems.forEach((item) => {
|
|
755
|
+
const label = item.group ?? "Ungrouped";
|
|
756
|
+
if (!groups.has(label)) groups.set(label, []);
|
|
757
|
+
groups.get(label).push(item);
|
|
758
|
+
});
|
|
759
|
+
element.setGroupedItems(
|
|
760
|
+
Array.from(groups, ([label, options]) => ({ label, options }))
|
|
761
|
+
);
|
|
762
|
+
} else {
|
|
763
|
+
element.setItems(sourceItems);
|
|
764
|
+
}
|
|
766
765
|
}
|
|
767
|
-
|
|
766
|
+
synchronizedSourceRef.current = sourceCandidate;
|
|
767
|
+
});
|
|
768
|
+
useEffect(() => {
|
|
769
|
+
var _a2;
|
|
770
|
+
const element = elementRef.current;
|
|
771
|
+
if (!element || !isElementUsable || isControlled || hasAppliedInitialValueRef.current) return;
|
|
772
|
+
if (internalValue === void 0) return;
|
|
773
|
+
const values = Array.isArray(internalValue) ? internalValue : [internalValue];
|
|
774
|
+
const currentValues = ((_a2 = element.getSelectedValues) == null ? void 0 : _a2.call(element)) || [];
|
|
775
|
+
if (!areValuesEqual(values, currentValues)) element.setSelectedValues(values);
|
|
776
|
+
hasAppliedInitialValueRef.current = true;
|
|
777
|
+
}, [isElementUsable, isControlled, internalValue, areValuesEqual]);
|
|
768
778
|
useEffect(() => {
|
|
769
779
|
var _a2;
|
|
770
780
|
const element = elementRef.current;
|
|
@@ -778,99 +788,6 @@ const Select = forwardRef((props, ref) => {
|
|
|
778
788
|
}
|
|
779
789
|
}
|
|
780
790
|
}, [value, isControlled, isElementUsable, areValuesEqual]);
|
|
781
|
-
useEffect(() => {
|
|
782
|
-
const element = elementRef.current;
|
|
783
|
-
if (!element || !isElementUsable || !element.updateConfig) return;
|
|
784
|
-
const config = {
|
|
785
|
-
searchable,
|
|
786
|
-
placeholder,
|
|
787
|
-
virtualize: virtualized,
|
|
788
|
-
estimatedItemHeight,
|
|
789
|
-
enabled: !disabled,
|
|
790
|
-
dropdownPlacement: {
|
|
791
|
-
mode: resolvedDropdownPlacement
|
|
792
|
-
},
|
|
793
|
-
selection: {
|
|
794
|
-
...selectionConfig,
|
|
795
|
-
mode: multiple ? "multi" : "single",
|
|
796
|
-
maxSelections,
|
|
797
|
-
removeButtonIcon: typeof removeButtonIcon === "string" ? removeButtonIcon : void 0,
|
|
798
|
-
disabledOptionBehavior,
|
|
799
|
-
showSelectedIndicator,
|
|
800
|
-
toggleOnTriggerClick
|
|
801
|
-
},
|
|
802
|
-
direction,
|
|
803
|
-
multiSelectDisplay,
|
|
804
|
-
infiniteScroll: {
|
|
805
|
-
enabled: infiniteScroll,
|
|
806
|
-
pageSize
|
|
807
|
-
},
|
|
808
|
-
scrollToSelected: {
|
|
809
|
-
enabled: true,
|
|
810
|
-
...scrollToSelected
|
|
811
|
-
},
|
|
812
|
-
styles: stylesConfig,
|
|
813
|
-
clearControl: {
|
|
814
|
-
enabled: clearable,
|
|
815
|
-
clearSelection: clearSelectionOnClear,
|
|
816
|
-
clearSearch: clearSearchOnClear,
|
|
817
|
-
ariaLabel: clearAriaLabel,
|
|
818
|
-
icon: clearIcon
|
|
819
|
-
},
|
|
820
|
-
tracking: {
|
|
821
|
-
enabled: trackingEnabled,
|
|
822
|
-
events: trackEvents,
|
|
823
|
-
styling: trackStyling,
|
|
824
|
-
limitations: trackLimitations,
|
|
825
|
-
emitDiagnostics,
|
|
826
|
-
maxEntries: trackingMaxEntries
|
|
827
|
-
},
|
|
828
|
-
limitations: {
|
|
829
|
-
policies: limitationPolicies,
|
|
830
|
-
autoMitigateRuntimeModeSwitch
|
|
831
|
-
}
|
|
832
|
-
};
|
|
833
|
-
applyInstanceConfig(element, config);
|
|
834
|
-
if (coreConfig) {
|
|
835
|
-
applyInstanceConfig(element, coreConfig);
|
|
836
|
-
}
|
|
837
|
-
}, [
|
|
838
|
-
searchable,
|
|
839
|
-
placeholder,
|
|
840
|
-
virtualized,
|
|
841
|
-
estimatedItemHeight,
|
|
842
|
-
disabled,
|
|
843
|
-
multiple,
|
|
844
|
-
maxSelections,
|
|
845
|
-
selectionConfig,
|
|
846
|
-
multiSelectDisplay,
|
|
847
|
-
scrollToSelected,
|
|
848
|
-
stylesConfig,
|
|
849
|
-
coreConfig,
|
|
850
|
-
removeButtonIcon,
|
|
851
|
-
disabledOptionBehavior,
|
|
852
|
-
showSelectedIndicator,
|
|
853
|
-
toggleOnTriggerClick,
|
|
854
|
-
infiniteScroll,
|
|
855
|
-
pageSize,
|
|
856
|
-
clearable,
|
|
857
|
-
clearSelectionOnClear,
|
|
858
|
-
clearSearchOnClear,
|
|
859
|
-
clearAriaLabel,
|
|
860
|
-
clearIcon,
|
|
861
|
-
trackingEnabled,
|
|
862
|
-
trackEvents,
|
|
863
|
-
trackStyling,
|
|
864
|
-
trackLimitations,
|
|
865
|
-
emitDiagnostics,
|
|
866
|
-
trackingMaxEntries,
|
|
867
|
-
limitationPolicies,
|
|
868
|
-
autoMitigateRuntimeModeSwitch,
|
|
869
|
-
direction,
|
|
870
|
-
resolvedDropdownPlacement,
|
|
871
|
-
isElementUsable,
|
|
872
|
-
applyInstanceConfig
|
|
873
|
-
]);
|
|
874
791
|
useEffect(() => {
|
|
875
792
|
const element = elementRef.current;
|
|
876
793
|
const shadow = element == null ? void 0 : element.shadowRoot;
|
|
@@ -954,11 +871,6 @@ const Select = forwardRef((props, ref) => {
|
|
|
954
871
|
isElementUsable,
|
|
955
872
|
acceptedProtocol,
|
|
956
873
|
acknowledgedRequested,
|
|
957
|
-
coreConfig,
|
|
958
|
-
items,
|
|
959
|
-
groupedItems,
|
|
960
|
-
value,
|
|
961
|
-
defaultValue,
|
|
962
874
|
loading,
|
|
963
875
|
consumerAriaBusy,
|
|
964
876
|
syncHostBusy,
|