@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 CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Select component for React applications. The shared core has scoped automated Phase 4 browser coverage; complete React integration parity and manual assistive-technology certification remain unverified.
4
4
 
5
- > **Upcoming web release:** React `1.12.0` and Core `1.17.0` are release candidates, not yet available from npm. Their cumulative changes and qualification limits are tracked in the [web release checklist](../../docs/releases/WEB-1.17.0-RELEASE.md).
5
+ > **Web release:** React `1.12.0` and Core `1.17.0` are available from npm. This release adds the React remove-button node API and horizontal latest-chip auto-scroll; see the [web release record](../../docs/releases/WEB-1.17.0-RELEASE.md).
6
6
 
7
7
  > Large-list status: the public `virtualized` prop enables legacy chunked rendering for large flat lists; it does not window rows to the viewport, and all results may eventually be mounted. True viewport virtualization remains guarded by a private test seam and is not a supported production mode. The shared core passed its scoped Phase 4 automated browser matrix in Chromium, Firefox, and WebKit; this does not certify every React integration, minimum browser versions, or WCAG conformance. Manual assistive-technology assessment remains pending. See the [current limitation record](../../docs/KNOWN-LIMITATIONS.md#viewport-virtualization-status).
8
8
 
@@ -176,6 +176,14 @@ export function RemoteSelect() {
176
176
 
177
177
  The coordinator rejects stale responses by request ID and query generation; the host should still abort cancelled network work to save resources. An accepted response does not mean projection is finished: observe `onDataProjection` for the projection result. A failed request remains failed until a new explicit request is made; the sample deliberately does not retry automatically.
178
178
 
179
+ ### React item synchronization and acknowledged pagination
180
+
181
+ The adapter treats React props as the source snapshot and the Core data coordinator as the owner of accepted acknowledged responses. Rerendering with a newly allocated array of equivalent plain-object records does not call `setItems()` and cannot reset pages accepted by Core. Meaningful changes to an item's enumerable fields, nested plain-object metadata, array metadata, or group structure synchronize as source updates; an empty array is also an intentional update.
182
+
183
+ Use immutable plain-object item records. Functions and non-plain metadata values such as `Date`, `Map`, and class instances compare by identity, so memoize them if they are part of item metadata. Enumerable symbol keys and accessor identity are included in comparison. When data is semantically unchanged, React cannot infer that the application intends to restart pagination; initiate a new acknowledged search/generation for that intent instead of relying on a render or a fresh array.
184
+
185
+ The adapter applies configuration, source data, and controlled selection through separate lifecycle paths. Fresh equivalent configuration objects and inline React `removeButtonIcon` nodes do not reapply Core configuration. Actual selection, layout, styling, disabled-state, and data-loading configuration changes remain active. See the [React data synchronization ownership record](../../docs/architecture/REACT-DATA-SYNC-OWNERSHIP-107.md).
186
+
179
187
  ### Other useful scenarios
180
188
 
181
189
  - **Terminal empty remote search (#92):** When the host completes the matching acknowledged request with `status: 'exhausted'`, `items: []`, and `hasMore: false`, Core displays the query-specific no-results message after successful projection. React consumers do not need a manual rerender, popup toggle, or `setItems([])` workaround. Wait for `onDataProjection` with `status: 'complete'` before relying on the projected DOM; `completeDataRequest()` returning `accepted` reports response acceptance, not DOM settlement. An empty page with `status: 'empty'` and `hasMore: true` is nonterminal. This guidance does not include the separate React #85 fix.
@@ -219,9 +227,9 @@ Use `contentMode: 'replace'` when accessible `loadingContent` should be the only
219
227
 
220
228
  `minDisplayTime` is a presentation policy for the busy bucket, not a request delay. Request acceptance, pagination state, and `aria-busy` update as soon as the request completes. The dedicated `Searching...` view remains unchanged and is not replaced by these props.
221
229
 
222
- ### Latest-chip auto-scroll (React 1.12.0 candidate; Issue #100)
230
+ ### Latest-chip auto-scroll (React 1.12.0; Issue #100)
223
231
 
224
- In horizontal multi-select mode, `multiSelectDisplay.scrollToLatestChip` reveals a newly selected chip. It is opt-in and respects reduced-motion preferences. This behavior requires the pending Core `1.17.0` release; the adapter versions listed in the [web release checklist](../../docs/releases/WEB-1.17.0-RELEASE.md) are not yet on npm.
232
+ In horizontal multi-select mode, `multiSelectDisplay.scrollToLatestChip` reveals a newly selected chip. It is opt-in and respects reduced-motion preferences. It is available with Core `1.17.0`.
225
233
 
226
234
  ```tsx
227
235
  <Select
@@ -236,7 +244,7 @@ In horizontal multi-select mode, `multiSelectDisplay.scrollToLatestChip` reveals
236
244
  />
237
245
  ```
238
246
 
239
- ### Custom empty-state renderer (React 1.12.0 candidate; Issue #93)
247
+ ### Custom empty-state renderer (React 1.12.0; Issue #93)
240
248
 
241
249
  `emptyStateRenderer` receives Core's readonly `{ query, reason }` context only while a terminal empty state is active. React renders its result in Core's native `empty-state` slot; omit the prop to keep the built-in fallback. `onEmptyStateChange` receives the new context and receives `null` when the empty state clears. The imperative handle also exposes `getEmptyStateContext()`.
242
250
 
@@ -1881,11 +1889,11 @@ When rendering custom option content, set `classMap.active` to the class names u
1881
1889
 
1882
1890
  The option's `data-sm-state`, `aria-selected`, and classes reflect independent active/selected semantics. The fix is in Core, not in React's renderer. See [Issue #82](https://github.com/navidrezadoost/Smilodon/issues/82) and the [Core rendering guide](../core/README.md#active-state-on-custom-option-roots).
1883
1891
 
1884
- ### Acknowledged pagination on React rerenders — Issue #85 (unreleased)
1892
+ ### Acknowledged data synchronization on React rerenders — Issue #107
1885
1893
 
1886
- The reported local fix for [Issue #85](https://github.com/navidrezadoost/Smilodon/issues/85) is qualified **but not yet pushed, merged, or published**. In acknowledged loading, React's `items` prop can supply the initial page while Core accepts cumulative pages using `completeDataRequest()`. Equivalent or newly allocated `config`, `multiSelectDisplay`, and `disabledOptionBehavior` objects must not force Core to revert its accepted cumulative snapshot to the initial `items`.
1894
+ In acknowledged loading, Core owns the cumulative accepted result pages, while React owns the source records and configuration passed by the application. React `1.12.1` compares incoming source/configuration values with the last values it successfully synchronized. Equivalent newly allocated arrays and plain configuration objects do not reset accepted pages during an incidental rerender; changed item fields, grouping, and an explicit empty source still synchronize.
1887
1895
 
1888
- The pending fix moves `items`/`groupedItems` synchronization into one identity-guarded effect, independent of presentation configuration, and applies uncontrolled `defaultValue` after item registration. New `items` or `groupedItems` identities still represent deliberate updates; `setItems()` alone is not an acknowledged coordinator reset. Keep input references stable where the input is unchanged, complete requests with their exact request IDs and generations, and consult the final release notes before expecting this fix in published packages.
1896
+ Controlled selection remains synchronized separately. Core's acknowledged request protocol and imperative `setItems()` behavior are unchanged. Functions and non-plain metadata values compare by identity; keep them stable when they have not changed. Consumers should replace records immutably when changing their contents. See [Issue #107](https://github.com/navidrezadoost/Smilodon/issues/107), the [implementation and qualification record](../../docs/architecture/REACT-DATA-SYNC-OWNERSHIP-107.md), and the [React 1.12.1 release record](../../docs/releases/REACT-1.12.1-RELEASE.md).
1889
1897
 
1890
1898
  ## Styling
1891
1899
 
package/dist/index.cjs CHANGED
@@ -41,6 +41,64 @@ function isPlainRecord(value) {
41
41
  const prototype = Object.getPrototypeOf(value);
42
42
  return prototype === Object.prototype || prototype === null;
43
43
  }
44
+ function areSemanticallyEqual(left, right, seen = /* @__PURE__ */ new WeakMap()) {
45
+ var _a;
46
+ if (Object.is(left, right)) return true;
47
+ if (left === null || right === null || typeof left !== "object" || typeof right !== "object") {
48
+ return false;
49
+ }
50
+ const leftArray = Array.isArray(left);
51
+ const rightArray = Array.isArray(right);
52
+ if (leftArray !== rightArray) return false;
53
+ if (!leftArray && (!isPlainRecord(left) || !isPlainRecord(right))) return false;
54
+ if (leftArray && !Array.isArray(right)) return false;
55
+ if (leftArray && rightArray && left.length !== right.length) return false;
56
+ const leftPrototype = Object.getPrototypeOf(left);
57
+ const rightPrototype = Object.getPrototypeOf(right);
58
+ if (leftPrototype !== rightPrototype && !(isPlainRecord(left) && isPlainRecord(right))) return false;
59
+ const prior = (_a = seen.get(left)) == null ? void 0 : _a.get(right);
60
+ if (prior !== void 0) return prior;
61
+ let rightPairs = seen.get(left);
62
+ if (!rightPairs) {
63
+ rightPairs = /* @__PURE__ */ new WeakMap();
64
+ seen.set(left, rightPairs);
65
+ }
66
+ rightPairs.set(right, true);
67
+ const enumerableKeys = (value) => Reflect.ownKeys(value).filter((key) => {
68
+ var _a2;
69
+ return (_a2 = Object.getOwnPropertyDescriptor(value, key)) == null ? void 0 : _a2.enumerable;
70
+ });
71
+ const leftKeys = enumerableKeys(left);
72
+ const rightKeys = enumerableKeys(right);
73
+ const rightKeySet = new Set(rightKeys);
74
+ if (leftKeys.length !== rightKeys.length) {
75
+ rightPairs.set(right, false);
76
+ return false;
77
+ }
78
+ for (const key of leftKeys) {
79
+ if (!rightKeySet.has(key)) {
80
+ rightPairs.set(right, false);
81
+ return false;
82
+ }
83
+ const leftDescriptor = Object.getOwnPropertyDescriptor(left, key);
84
+ const rightDescriptor = Object.getOwnPropertyDescriptor(right, key);
85
+ if ("value" in leftDescriptor !== "value" in rightDescriptor) {
86
+ rightPairs.set(right, false);
87
+ return false;
88
+ }
89
+ if ("value" in leftDescriptor) {
90
+ if (!areSemanticallyEqual(leftDescriptor.value, rightDescriptor.value, seen)) {
91
+ rightPairs.set(right, false);
92
+ return false;
93
+ }
94
+ } else if (leftDescriptor.get !== rightDescriptor.get || leftDescriptor.set !== rightDescriptor.set) {
95
+ rightPairs.set(right, false);
96
+ return false;
97
+ }
98
+ }
99
+ return true;
100
+ }
101
+ const EMPTY_ITEMS = [];
44
102
  function isBusyToken(value) {
45
103
  return value === true || value === "true";
46
104
  }
@@ -52,7 +110,7 @@ function composeBusyToken(consumerValue, externalBusy) {
52
110
  const Select = React.forwardRef((props, ref) => {
53
111
  var _a, _b, _c;
54
112
  const {
55
- items = [],
113
+ items = EMPTY_ITEMS,
56
114
  groupedItems,
57
115
  value,
58
116
  defaultValue,
@@ -639,156 +697,108 @@ const Select = React.forwardRef((props, ref) => {
639
697
  return (_a2 = activeListenersRef.current) == null ? void 0 : _a2.dispose();
640
698
  };
641
699
  }, []);
642
- React.useEffect(() => {
643
- var _a2;
644
- const element = elementRef.current;
645
- if (!element || !isElementUsable) return;
646
- if (!element.setItems) {
647
- console.warn("Enhanced select element not fully initialized yet");
648
- return;
649
- }
650
- if (groupedItems) {
651
- element.setGroupedItems(groupedItems);
652
- } else if (items.length > 0) {
653
- element.setItems(items);
654
- }
655
- const config = {
656
- searchable,
657
- placeholder,
658
- virtualize: virtualized,
659
- estimatedItemHeight,
660
- enabled: !disabled,
661
- dropdownPlacement: {
662
- mode: resolvedDropdownPlacement
663
- },
664
- selection: {
665
- ...selectionConfig,
666
- mode: multiple ? "multi" : "single",
667
- maxSelections,
668
- removeButtonIcon: typeof removeButtonIcon === "string" ? removeButtonIcon : void 0,
669
- disabledOptionBehavior,
670
- showSelectedIndicator,
671
- toggleOnTriggerClick
672
- },
673
- direction,
674
- multiSelectDisplay,
675
- infiniteScroll: {
676
- enabled: infiniteScroll,
677
- pageSize
678
- },
679
- scrollToSelected: {
680
- enabled: true,
681
- ...scrollToSelected
682
- },
683
- creatable,
684
- styles: stylesConfig,
685
- clearControl: {
686
- enabled: clearable,
687
- clearSelection: clearSelectionOnClear,
688
- clearSearch: clearSearchOnClear,
689
- ariaLabel: clearAriaLabel,
690
- icon: clearIcon
691
- },
692
- tracking: {
693
- enabled: trackingEnabled,
694
- events: trackEvents,
695
- styling: trackStyling,
696
- limitations: trackLimitations,
697
- emitDiagnostics,
698
- maxEntries: trackingMaxEntries
699
- },
700
- limitations: {
701
- policies: limitationPolicies,
702
- autoMitigateRuntimeModeSwitch
703
- }
704
- };
705
- applyInstanceConfig(element, config);
706
- if (coreConfig) {
707
- applyInstanceConfig(element, coreConfig);
708
- }
709
- if (!isControlled && !hasAppliedInitialValueRef.current && internalValue !== void 0) {
710
- const values = Array.isArray(internalValue) ? internalValue : [internalValue];
711
- const currentValues = ((_a2 = element.getSelectedValues) == null ? void 0 : _a2.call(element)) || [];
712
- if (!areValuesEqual(values, currentValues)) {
713
- element.setSelectedValues(values);
714
- }
715
- hasAppliedInitialValueRef.current = true;
716
- }
717
- if (error) {
718
- element.setError(errorMessage || "Invalid selection");
719
- } else {
720
- element.clearError();
721
- }
722
- if (required) {
723
- element.setRequired(true);
724
- }
725
- }, [
726
- isElementUsable,
727
- items,
728
- groupedItems,
700
+ const componentConfig = {
729
701
  searchable,
730
702
  placeholder,
731
- virtualized,
703
+ virtualize: virtualized,
732
704
  estimatedItemHeight,
733
- disabled,
734
- multiple,
735
- maxSelections,
736
- selectionConfig,
705
+ enabled: !disabled,
706
+ dropdownPlacement: { mode: resolvedDropdownPlacement },
707
+ selection: {
708
+ ...selectionConfig,
709
+ mode: multiple ? "multi" : "single",
710
+ maxSelections,
711
+ removeButtonIcon: typeof removeButtonIcon === "string" ? removeButtonIcon : void 0,
712
+ disabledOptionBehavior,
713
+ showSelectedIndicator,
714
+ toggleOnTriggerClick
715
+ },
716
+ direction,
737
717
  multiSelectDisplay,
738
- scrollToSelected,
739
- stylesConfig,
740
- coreConfig,
741
- removeButtonIcon,
742
- disabledOptionBehavior,
743
- showSelectedIndicator,
744
- toggleOnTriggerClick,
745
- infiniteScroll,
746
- pageSize,
718
+ infiniteScroll: { enabled: infiniteScroll, pageSize },
719
+ scrollToSelected: { enabled: true, ...scrollToSelected },
747
720
  creatable,
748
- clearable,
749
- clearSelectionOnClear,
750
- clearSearchOnClear,
751
- clearAriaLabel,
752
- clearIcon,
753
- trackingEnabled,
754
- trackEvents,
755
- trackStyling,
756
- trackLimitations,
757
- emitDiagnostics,
758
- trackingMaxEntries,
759
- limitationPolicies,
760
- autoMitigateRuntimeModeSwitch,
761
- direction,
762
- resolvedDropdownPlacement,
763
- error,
764
- errorMessage,
765
- required,
766
- internalValue,
767
- isControlled,
768
- areValuesEqual,
769
- applyInstanceConfig
770
- ]);
721
+ styles: stylesConfig,
722
+ clearControl: {
723
+ enabled: clearable,
724
+ clearSelection: clearSelectionOnClear,
725
+ clearSearch: clearSearchOnClear,
726
+ ariaLabel: clearAriaLabel,
727
+ icon: clearIcon
728
+ },
729
+ tracking: {
730
+ enabled: trackingEnabled,
731
+ events: trackEvents,
732
+ styling: trackStyling,
733
+ limitations: trackLimitations,
734
+ emitDiagnostics,
735
+ maxEntries: trackingMaxEntries
736
+ },
737
+ limitations: { policies: limitationPolicies, autoMitigateRuntimeModeSwitch }
738
+ };
739
+ const configCandidate = { component: componentConfig, core: coreConfig };
740
+ const appliedConfigRef = React.useRef({ hasComponent: false, component: null, hasCore: false, core: void 0 });
741
+ React.useEffect(() => {
742
+ const element = elementRef.current;
743
+ if (!element || !isElementUsable || !element.updateConfig) return;
744
+ const previous = appliedConfigRef.current;
745
+ const componentChanged = !previous.hasComponent || !areSemanticallyEqual(previous.component, configCandidate.component);
746
+ const coreChanged = !previous.hasCore || !areSemanticallyEqual(previous.core, configCandidate.core);
747
+ if (!componentChanged && !coreChanged) return;
748
+ if (componentChanged) {
749
+ applyInstanceConfig(element, configCandidate.component);
750
+ if (configCandidate.core) applyInstanceConfig(element, configCandidate.core);
751
+ } else if (coreChanged) {
752
+ if (configCandidate.core) {
753
+ applyInstanceConfig(element, configCandidate.core);
754
+ } else {
755
+ applyInstanceConfig(element, configCandidate.component);
756
+ }
757
+ }
758
+ appliedConfigRef.current = {
759
+ hasComponent: true,
760
+ component: configCandidate.component,
761
+ hasCore: true,
762
+ core: configCandidate.core
763
+ };
764
+ });
765
+ const sourceCandidate = groupedItems !== void 0 ? { kind: "grouped", data: groupedItems } : { kind: "items", data: items };
766
+ const synchronizedSourceRef = React.useRef(null);
771
767
  React.useEffect(() => {
768
+ var _a2;
772
769
  const element = elementRef.current;
773
770
  if (!element || !isElementUsable || !element.setItems) return;
774
- if (groupedItems) {
775
- element.setGroupedItems(groupedItems);
776
- } else if (items && items.length && items[0] && items[0].group !== void 0) {
777
- const map = /* @__PURE__ */ new Map();
778
- items.forEach((it) => {
779
- const g = it.group ?? "Ungrouped";
780
- if (!map.has(g)) map.set(g, []);
781
- map.get(g).push(it);
782
- });
783
- const groups = Array.from(map.entries()).map(([label, options]) => ({
784
- label,
785
- options
786
- }));
787
- element.setGroupedItems(groups);
771
+ if (areSemanticallyEqual(synchronizedSourceRef.current, sourceCandidate)) return;
772
+ if (sourceCandidate.kind === "grouped") {
773
+ element.setGroupedItems(sourceCandidate.data);
788
774
  } else {
789
- element.setItems(items);
775
+ const sourceItems = sourceCandidate.data;
776
+ if (sourceItems.length > 0 && ((_a2 = sourceItems[0]) == null ? void 0 : _a2.group) !== void 0) {
777
+ const groups = /* @__PURE__ */ new Map();
778
+ sourceItems.forEach((item) => {
779
+ const label = item.group ?? "Ungrouped";
780
+ if (!groups.has(label)) groups.set(label, []);
781
+ groups.get(label).push(item);
782
+ });
783
+ element.setGroupedItems(
784
+ Array.from(groups, ([label, options]) => ({ label, options }))
785
+ );
786
+ } else {
787
+ element.setItems(sourceItems);
788
+ }
790
789
  }
791
- }, [items, groupedItems, isElementUsable]);
790
+ synchronizedSourceRef.current = sourceCandidate;
791
+ });
792
+ React.useEffect(() => {
793
+ var _a2;
794
+ const element = elementRef.current;
795
+ if (!element || !isElementUsable || isControlled || hasAppliedInitialValueRef.current) return;
796
+ if (internalValue === void 0) return;
797
+ const values = Array.isArray(internalValue) ? internalValue : [internalValue];
798
+ const currentValues = ((_a2 = element.getSelectedValues) == null ? void 0 : _a2.call(element)) || [];
799
+ if (!areValuesEqual(values, currentValues)) element.setSelectedValues(values);
800
+ hasAppliedInitialValueRef.current = true;
801
+ }, [isElementUsable, isControlled, internalValue, areValuesEqual]);
792
802
  React.useEffect(() => {
793
803
  var _a2;
794
804
  const element = elementRef.current;
@@ -802,99 +812,6 @@ const Select = React.forwardRef((props, ref) => {
802
812
  }
803
813
  }
804
814
  }, [value, isControlled, isElementUsable, areValuesEqual]);
805
- React.useEffect(() => {
806
- const element = elementRef.current;
807
- if (!element || !isElementUsable || !element.updateConfig) return;
808
- const config = {
809
- searchable,
810
- placeholder,
811
- virtualize: virtualized,
812
- estimatedItemHeight,
813
- enabled: !disabled,
814
- dropdownPlacement: {
815
- mode: resolvedDropdownPlacement
816
- },
817
- selection: {
818
- ...selectionConfig,
819
- mode: multiple ? "multi" : "single",
820
- maxSelections,
821
- removeButtonIcon: typeof removeButtonIcon === "string" ? removeButtonIcon : void 0,
822
- disabledOptionBehavior,
823
- showSelectedIndicator,
824
- toggleOnTriggerClick
825
- },
826
- direction,
827
- multiSelectDisplay,
828
- infiniteScroll: {
829
- enabled: infiniteScroll,
830
- pageSize
831
- },
832
- scrollToSelected: {
833
- enabled: true,
834
- ...scrollToSelected
835
- },
836
- styles: stylesConfig,
837
- clearControl: {
838
- enabled: clearable,
839
- clearSelection: clearSelectionOnClear,
840
- clearSearch: clearSearchOnClear,
841
- ariaLabel: clearAriaLabel,
842
- icon: clearIcon
843
- },
844
- tracking: {
845
- enabled: trackingEnabled,
846
- events: trackEvents,
847
- styling: trackStyling,
848
- limitations: trackLimitations,
849
- emitDiagnostics,
850
- maxEntries: trackingMaxEntries
851
- },
852
- limitations: {
853
- policies: limitationPolicies,
854
- autoMitigateRuntimeModeSwitch
855
- }
856
- };
857
- applyInstanceConfig(element, config);
858
- if (coreConfig) {
859
- applyInstanceConfig(element, coreConfig);
860
- }
861
- }, [
862
- searchable,
863
- placeholder,
864
- virtualized,
865
- estimatedItemHeight,
866
- disabled,
867
- multiple,
868
- maxSelections,
869
- selectionConfig,
870
- multiSelectDisplay,
871
- scrollToSelected,
872
- stylesConfig,
873
- coreConfig,
874
- removeButtonIcon,
875
- disabledOptionBehavior,
876
- showSelectedIndicator,
877
- toggleOnTriggerClick,
878
- infiniteScroll,
879
- pageSize,
880
- clearable,
881
- clearSelectionOnClear,
882
- clearSearchOnClear,
883
- clearAriaLabel,
884
- clearIcon,
885
- trackingEnabled,
886
- trackEvents,
887
- trackStyling,
888
- trackLimitations,
889
- emitDiagnostics,
890
- trackingMaxEntries,
891
- limitationPolicies,
892
- autoMitigateRuntimeModeSwitch,
893
- direction,
894
- resolvedDropdownPlacement,
895
- isElementUsable,
896
- applyInstanceConfig
897
- ]);
898
815
  React.useEffect(() => {
899
816
  const element = elementRef.current;
900
817
  const shadow = element == null ? void 0 : element.shadowRoot;
@@ -978,11 +895,6 @@ const Select = React.forwardRef((props, ref) => {
978
895
  isElementUsable,
979
896
  acceptedProtocol,
980
897
  acknowledgedRequested,
981
- coreConfig,
982
- items,
983
- groupedItems,
984
- value,
985
- defaultValue,
986
898
  loading,
987
899
  consumerAriaBusy,
988
900
  syncHostBusy,