@fluentui/react-context-selector 9.0.0-alpha.8 → 9.0.0-beta.3

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 (44) hide show
  1. package/CHANGELOG.json +716 -1
  2. package/CHANGELOG.md +318 -2
  3. package/README.md +20 -0
  4. package/dist/react-context-selector.d.ts +9 -0
  5. package/lib/createContext.js +10 -10
  6. package/lib/createContext.js.map +1 -1
  7. package/lib/index.d.ts +1 -0
  8. package/lib/index.js +1 -0
  9. package/lib/index.js.map +1 -1
  10. package/lib/tsdoc-metadata.json +1 -1
  11. package/lib/types.js.map +1 -1
  12. package/lib/useContextSelector.js +11 -11
  13. package/lib/useContextSelector.js.map +1 -1
  14. package/lib/useHasParentContext.d.ts +9 -0
  15. package/lib/useHasParentContext.js +16 -0
  16. package/lib/useHasParentContext.js.map +1 -0
  17. package/lib-commonjs/createContext.js +13 -13
  18. package/lib-commonjs/createContext.js.map +1 -1
  19. package/lib-commonjs/index.d.ts +1 -0
  20. package/lib-commonjs/index.js +4 -2
  21. package/lib-commonjs/index.js.map +1 -1
  22. package/lib-commonjs/types.js.map +1 -1
  23. package/lib-commonjs/useContextSelector.js +13 -13
  24. package/lib-commonjs/useContextSelector.js.map +1 -1
  25. package/lib-commonjs/useHasParentContext.d.ts +9 -0
  26. package/lib-commonjs/useHasParentContext.js +20 -0
  27. package/lib-commonjs/useHasParentContext.js.map +1 -0
  28. package/package.json +6 -7
  29. package/config/api-extractor.json +0 -3
  30. package/config/tests.js +0 -1
  31. package/etc/react-context-selector.api.md +0 -42
  32. package/just.config.ts +0 -3
  33. package/lib-amd/createContext.d.ts +0 -2
  34. package/lib-amd/createContext.js +0 -48
  35. package/lib-amd/createContext.js.map +0 -1
  36. package/lib-amd/index.d.ts +0 -3
  37. package/lib-amd/index.js +0 -9
  38. package/lib-amd/index.js.map +0 -1
  39. package/lib-amd/types.d.ts +0 -19
  40. package/lib-amd/types.js +0 -5
  41. package/lib-amd/types.js.map +0 -1
  42. package/lib-amd/useContextSelector.d.ts +0 -7
  43. package/lib-amd/useContextSelector.js +0 -71
  44. package/lib-amd/useContextSelector.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,12 +1,328 @@
1
1
  # Change Log - @fluentui/react-context-selector
2
2
 
3
- This log was last generated on Thu, 20 May 2021 07:34:56 GMT and should not be manually modified.
3
+ This log was last generated on Fri, 12 Nov 2021 12:33:31 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## [9.0.0-beta.3](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-beta.3)
8
+
9
+ Fri, 12 Nov 2021 12:33:31 GMT
10
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.0.0-beta.2..@fluentui/react-context-selector_v9.0.0-beta.3)
11
+
12
+ ### Changes
13
+
14
+ - Updated beta and RC components to ES2019 ([PR #20405](https://github.com/microsoft/fluentui/pull/20405) by gcox@microsoft.com)
15
+ - Bump @fluentui/react-utilities to v9.0.0-beta.3 ([PR #20593](https://github.com/microsoft/fluentui/pull/20593) by beachball)
16
+
17
+ ## [9.0.0-beta.2](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-beta.2)
18
+
19
+ Wed, 27 Oct 2021 12:14:24 GMT
20
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.0.0-beta.1..@fluentui/react-context-selector_v9.0.0-beta.2)
21
+
22
+ ### Changes
23
+
24
+ - Bump @fluentui/react-utilities to v9.0.0-beta.2 ([PR #20353](https://github.com/microsoft/fluentui/pull/20353) by beachball)
25
+
26
+ ## [9.0.0-beta.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-beta.1)
27
+
28
+ Wed, 06 Oct 2021 10:37:22 GMT
29
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.0.0-alpha.39..@fluentui/react-context-selector_v9.0.0-beta.1)
30
+
31
+ ### Changes
32
+
33
+ - Bump all v9 components to beta prerelease tag ([PR #20106](https://github.com/microsoft/fluentui/pull/20106) by lingfangao@hotmail.com)
34
+ - Bump @fluentui/react-utilities to v9.0.0-beta.1 ([PR #20106](https://github.com/microsoft/fluentui/pull/20106) by beachball)
35
+
36
+ ## [9.0.0-alpha.39](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.39)
37
+
38
+ Tue, 05 Oct 2021 09:28:07 GMT
39
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.0.0-alpha.38..@fluentui/react-context-selector_v9.0.0-alpha.39)
40
+
41
+ ### Changes
42
+
43
+ - Bump @fluentui/react-utilities to v9.0.0-alpha.56 ([PR #20081](https://github.com/microsoft/fluentui/pull/20081) by beachball)
44
+
45
+ ## [9.0.0-alpha.38](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.38)
46
+
47
+ Fri, 01 Oct 2021 14:13:08 GMT
48
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.0.0-alpha.36..@fluentui/react-context-selector_v9.0.0-alpha.38)
49
+
50
+ ### Changes
51
+
52
+ - Bump v9 prerelease versions to rerelease ([PR #20069](https://github.com/microsoft/fluentui/pull/20069) by lingfangao@hotmail.com)
53
+ - Bump @fluentui/react-utilities to v9.0.0-alpha.55 ([PR #20069](https://github.com/microsoft/fluentui/pull/20069) by beachball)
54
+
55
+ ## [9.0.0-alpha.36](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.36)
56
+
57
+ Mon, 27 Sep 2021 08:06:00 GMT
58
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.0.0-alpha.35..@fluentui/react-context-selector_v9.0.0-alpha.36)
59
+
60
+ ### Changes
61
+
62
+ - Bump @fluentui/react-utilities to v9.0.0-alpha.53 ([PR #19981](https://github.com/microsoft/fluentui/pull/19981) by beachball)
63
+
64
+ ## [9.0.0-alpha.35](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.35)
65
+
66
+ Fri, 24 Sep 2021 09:17:17 GMT
67
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.0.0-alpha.34..@fluentui/react-context-selector_v9.0.0-alpha.35)
68
+
69
+ ### Changes
70
+
71
+ - Bump @fluentui/react-utilities to v9.0.0-alpha.52 ([PR #19950](https://github.com/microsoft/fluentui/pull/19950) by beachball)
72
+
73
+ ## [9.0.0-alpha.34](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.34)
74
+
75
+ Thu, 23 Sep 2021 08:21:34 GMT
76
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.0.0-alpha.33..@fluentui/react-context-selector_v9.0.0-alpha.34)
77
+
78
+ ### Changes
79
+
80
+ - Bump @fluentui/react-utilities to v9.0.0-alpha.51 ([commit](https://github.com/microsoft/fluentui/commit/95682da34c48813f7658032ae490d21d2f363b90) by beachball)
81
+
82
+ ## [9.0.0-alpha.33](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.33)
83
+
84
+ Wed, 22 Sep 2021 10:10:07 GMT
85
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.0.0-alpha.32..@fluentui/react-context-selector_v9.0.0-alpha.33)
86
+
87
+ ### Changes
88
+
89
+ - Bump @fluentui/react-utilities to v9.0.0-alpha.50 ([commit](https://github.com/microsoft/fluentui/commit/bc3f1ec72fc7784a558b0dd6598ee0662f4649c1) by beachball)
90
+
91
+ ## [9.0.0-alpha.32](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.32)
92
+
93
+ Fri, 17 Sep 2021 07:35:26 GMT
94
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.0.0-alpha.31..@fluentui/react-context-selector_v9.0.0-alpha.32)
95
+
96
+ ### Changes
97
+
98
+ - Bump @fluentui/react-context-selector to v9.0.0-alpha.32 ([PR #19840](https://github.com/microsoft/fluentui/pull/19840) by Humberto.Morimoto@microsoft.com)
99
+
100
+ ## [9.0.0-alpha.31](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.31)
101
+
102
+ Thu, 16 Sep 2021 07:38:39 GMT
103
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.0.0-alpha.30..@fluentui/react-context-selector_v9.0.0-alpha.31)
104
+
105
+ ### Changes
106
+
107
+ - Bump @fluentui/react-context-selector to v9.0.0-alpha.31 ([PR #19815](https://github.com/microsoft/fluentui/pull/19815) by behowell@microsoft.com)
108
+
109
+ ## [9.0.0-alpha.30](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.30)
110
+
111
+ Tue, 14 Sep 2021 20:09:02 GMT
112
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.0.0-alpha.29..@fluentui/react-context-selector_v9.0.0-alpha.30)
113
+
114
+ ### Changes
115
+
116
+ - Bump @fluentui/react-context-selector to v9.0.0-alpha.30 ([PR #19155](https://github.com/microsoft/fluentui/pull/19155) by bsunderhus@microsoft.com)
117
+
118
+ ## [9.0.0-alpha.29](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.29)
119
+
120
+ Fri, 10 Sep 2021 16:31:53 GMT
121
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.0.0-alpha.28..@fluentui/react-context-selector_v9.0.0-alpha.29)
122
+
123
+ ### Changes
124
+
125
+ - chore(v9): Move all internal v9 dependencies from caret to fixed version ([PR #19748](https://github.com/microsoft/fluentui/pull/19748) by lingfangao@hotmail.com)
126
+ - Bump @fluentui/react-context-selector to v9.0.0-alpha.29 ([PR #19748](https://github.com/microsoft/fluentui/pull/19748) by lingfangao@hotmail.com)
127
+
128
+ ## [9.0.0-alpha.28](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.28)
129
+
130
+ Fri, 10 Sep 2021 07:39:51 GMT
131
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.0.0-alpha.27..@fluentui/react-context-selector_v9.0.0-alpha.28)
132
+
133
+ ### Changes
134
+
135
+ - Bump @fluentui/react-utilities to v9.0.0-alpha.45 ([PR #19642](https://github.com/microsoft/fluentui/pull/19642) by behowell@microsoft.com)
136
+
137
+ ## [9.0.0-alpha.27](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.27)
138
+
139
+ Mon, 06 Sep 2021 07:34:53 GMT
140
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.0.0-alpha.26..@fluentui/react-context-selector_v9.0.0-alpha.27)
141
+
142
+ ### Changes
143
+
144
+ - Bump @fluentui/react-utilities to v9.0.0-alpha.44 ([PR #19640](https://github.com/microsoft/fluentui/pull/19640) by lingfangao@hotmail.com)
145
+
146
+ ## [9.0.0-alpha.26](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.26)
147
+
148
+ Wed, 01 Sep 2021 07:39:56 GMT
149
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.0.0-alpha.25..@fluentui/react-context-selector_v9.0.0-alpha.26)
150
+
151
+ ### Changes
152
+
153
+ - Bump @fluentui/react-utilities to v9.0.0-alpha.43 ([PR #19483](https://github.com/microsoft/fluentui/pull/19483) by bsunderhus@microsoft.com)
154
+
155
+ ## [9.0.0-alpha.25](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.25)
156
+
157
+ Tue, 31 Aug 2021 07:37:47 GMT
158
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.0.0-alpha.24..@fluentui/react-context-selector_v9.0.0-alpha.25)
159
+
160
+ ### Changes
161
+
162
+ - Bump @fluentui/react-utilities to v9.0.0-alpha.42 ([PR #19556](https://github.com/microsoft/fluentui/pull/19556) by lingfan.gao@microsoft.com)
163
+
164
+ ## [9.0.0-alpha.24](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.24)
165
+
166
+ Fri, 20 Aug 2021 07:37:28 GMT
167
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.0.0-alpha.23..@fluentui/react-context-selector_v9.0.0-alpha.24)
168
+
169
+ ### Changes
170
+
171
+ - Update .npmignore ([PR #19441](https://github.com/microsoft/fluentui/pull/19441) by elcraig@microsoft.com)
172
+
173
+ ## [9.0.0-alpha.23](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.23)
174
+
175
+ Thu, 19 Aug 2021 07:41:35 GMT
176
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.0.0-alpha.22..@fluentui/react-context-selector_v9.0.0-alpha.23)
177
+
178
+ ### Changes
179
+
180
+ - Bump @fluentui/react-utilities to v9.0.0-alpha.39 ([PR #19273](https://github.com/microsoft/fluentui/pull/19273) by bsunderhus@microsoft.com)
181
+
182
+ ## [9.0.0-alpha.22](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.22)
183
+
184
+ Fri, 06 Aug 2021 07:35:14 GMT
185
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.0.0-alpha.21..@fluentui/react-context-selector_v9.0.0-alpha.22)
186
+
187
+ ### Changes
188
+
189
+ - Bump @fluentui/react-utilities to v9.0.0-alpha.38 ([PR #19189](https://github.com/microsoft/fluentui/pull/19189) by bsunderhus@microsoft.com)
190
+
191
+ ## [9.0.0-alpha.21](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.21)
192
+
193
+ Tue, 03 Aug 2021 07:39:30 GMT
194
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.0.0-alpha.20..@fluentui/react-context-selector_v9.0.0-alpha.21)
195
+
196
+ ### Patches
197
+
198
+ - Bump @fluentui/eslint-plugin to v1.3.3 ([PR #19169](https://github.com/microsoft/fluentui/pull/19169) by behowell@microsoft.com)
199
+ - Bump @fluentui/scripts to v1.0.0 ([PR #19169](https://github.com/microsoft/fluentui/pull/19169) by behowell@microsoft.com)
200
+
201
+ ### Changes
202
+
203
+ - Bump @fluentui/react-utilities to v9.0.0-alpha.37 ([PR #19169](https://github.com/microsoft/fluentui/pull/19169) by behowell@microsoft.com)
204
+
205
+ ## [9.0.0-alpha.20](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.20)
206
+
207
+ Mon, 02 Aug 2021 07:36:20 GMT
208
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.0.0-alpha.19..@fluentui/react-context-selector_v9.0.0-alpha.20)
209
+
210
+ ### Changes
211
+
212
+ - Bump @fluentui/react-utilities to v9.0.0-alpha.36 ([PR #19204](https://github.com/microsoft/fluentui/pull/19204) by lingfan.gao@microsoft.com)
213
+
214
+ ## [9.0.0-alpha.19](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.19)
215
+
216
+ Fri, 23 Jul 2021 07:38:19 GMT
217
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.0.0-alpha.18..@fluentui/react-context-selector_v9.0.0-alpha.19)
218
+
219
+ ### Changes
220
+
221
+ - Bump @fluentui/react-utilities to v9.0.0-alpha.35 ([PR #18610](https://github.com/microsoft/fluentui/pull/18610) by behowell@microsoft.com)
222
+
223
+ ## [9.0.0-alpha.18](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.18)
224
+
225
+ Thu, 22 Jul 2021 07:36:55 GMT
226
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.0.0-alpha.17..@fluentui/react-context-selector_v9.0.0-alpha.18)
227
+
228
+ ### Changes
229
+
230
+ - Bump @fluentui/react-utilities to v9.0.0-alpha.34 ([PR #19023](https://github.com/microsoft/fluentui/pull/19023) by behowell@microsoft.com)
231
+
232
+ ## [9.0.0-alpha.17](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.17)
233
+
234
+ Thu, 15 Jul 2021 07:36:18 GMT
235
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.0.0-alpha.16..@fluentui/react-context-selector_v9.0.0-alpha.17)
236
+
237
+ ### Changes
238
+
239
+ - feat(useHasParentContext): new hook to determine if a context provider exists as parent ([PR #18812](https://github.com/microsoft/fluentui/pull/18812) by lingfan.gao@microsoft.com)
240
+
241
+ ## [9.0.0-alpha.16](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.16)
242
+
243
+ Fri, 09 Jul 2021 07:39:31 GMT
244
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.0.0-alpha.15..@fluentui/react-context-selector_v9.0.0-alpha.16)
245
+
246
+ ### Patches
247
+
248
+ - Bump @fluentui/eslint-plugin to v1.3.2 ([PR #18808](https://github.com/microsoft/fluentui/pull/18808) by martinhochel@microsoft.com)
249
+ - Bump @fluentui/scripts to v1.0.0 ([PR #18808](https://github.com/microsoft/fluentui/pull/18808) by martinhochel@microsoft.com)
250
+
251
+ ### Changes
252
+
253
+ - Bump @fluentui/react-utilities to v9.0.0-alpha.32 ([PR #18808](https://github.com/microsoft/fluentui/pull/18808) by martinhochel@microsoft.com)
254
+
255
+ ## [9.0.0-alpha.15](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.15)
256
+
257
+ Fri, 02 Jul 2021 23:15:55 GMT
258
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.0.0-alpha.14..@fluentui/react-context-selector_v9.0.0-alpha.15)
259
+
260
+ ### Changes
261
+
262
+ - Bump @fluentui/react-utilities to v9.0.0-alpha.31 ([PR #18721](https://github.com/microsoft/fluentui/pull/18721) by bsunderhus@microsoft.com)
263
+
264
+ ## [9.0.0-alpha.14](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.14)
265
+
266
+ Fri, 02 Jul 2021 07:37:06 GMT
267
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.0.0-alpha.13..@fluentui/react-context-selector_v9.0.0-alpha.14)
268
+
269
+ ### Changes
270
+
271
+ - Bump @fluentui/react-utilities to v9.0.0-alpha.30 ([PR #18796](https://github.com/microsoft/fluentui/pull/18796) by bsunderhus@microsoft.com)
272
+
273
+ ## [9.0.0-alpha.13](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.13)
274
+
275
+ Tue, 15 Jun 2021 07:40:20 GMT
276
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.0.0-alpha.12..@fluentui/react-context-selector_v9.0.0-alpha.13)
277
+
278
+ ### Changes
279
+
280
+ - Bump @fluentui/react-utilities to v9.0.0-alpha.29 ([PR #18521](https://github.com/microsoft/fluentui/pull/18521) by behowell@microsoft.com)
281
+
282
+ ## [9.0.0-alpha.12](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.12)
283
+
284
+ Mon, 07 Jun 2021 07:38:15 GMT
285
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.0.0-alpha.11..@fluentui/react-context-selector_v9.0.0-alpha.12)
286
+
287
+ ### Patches
288
+
289
+ - Bump @fluentui/eslint-plugin to v1.3.1 ([PR #18437](https://github.com/microsoft/fluentui/pull/18437) by martinhochel@microsoft.com)
290
+ - Bump @fluentui/scripts to v1.0.0 ([PR #18437](https://github.com/microsoft/fluentui/pull/18437) by martinhochel@microsoft.com)
291
+
292
+ ### Changes
293
+
294
+ - Bump @fluentui/react-utilities to v9.0.0-alpha.28 ([PR #18437](https://github.com/microsoft/fluentui/pull/18437) by martinhochel@microsoft.com)
295
+
296
+ ## [9.0.0-alpha.11](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.11)
297
+
298
+ Fri, 04 Jun 2021 07:37:23 GMT
299
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.0.0-alpha.10..@fluentui/react-context-selector_v9.0.0-alpha.11)
300
+
301
+ ### Changes
302
+
303
+ - Bump @fluentui/react-utilities to v9.0.0-alpha.27 ([PR #18168](https://github.com/microsoft/fluentui/pull/18168) by Humberto.Morimoto@microsoft.com)
304
+
305
+ ## [9.0.0-alpha.10](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.10)
306
+
307
+ Wed, 26 May 2021 07:35:43 GMT
308
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.0.0-alpha.9..@fluentui/react-context-selector_v9.0.0-alpha.10)
309
+
310
+ ### Changes
311
+
312
+ - Bump @fluentui/react-utilities to v9.0.0-alpha.25 ([PR #18323](https://github.com/microsoft/fluentui/pull/18323) by lingfan.gao@microsoft.com)
313
+
314
+ ## [9.0.0-alpha.9](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.9)
315
+
316
+ Fri, 21 May 2021 07:34:54 GMT
317
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.0.0-alpha.8..@fluentui/react-context-selector_v9.0.0-alpha.9)
318
+
319
+ ### Changes
320
+
321
+ - Bump @fluentui/react-utilities to v9.0.0-alpha.24 ([PR #18259](https://github.com/microsoft/fluentui/pull/18259) by behowell@microsoft.com)
322
+
7
323
  ## [9.0.0-alpha.8](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.8)
8
324
 
9
- Thu, 20 May 2021 07:34:56 GMT
325
+ Thu, 20 May 2021 07:41:54 GMT
10
326
  [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.0.0-alpha.7..@fluentui/react-context-selector_v9.0.0-alpha.8)
11
327
 
12
328
  ### Patches
package/README.md CHANGED
@@ -25,6 +25,8 @@ yarn add @fluentui/react-context-selector
25
25
 
26
26
  ## Usage
27
27
 
28
+ ### Getting started
29
+
28
30
  ```tsx
29
31
  import * as React from 'react';
30
32
  import { createContext, useContextSelector, ContextSelector } from '@fluentui/react-context-selector';
@@ -86,6 +88,24 @@ export default function App() {
86
88
  }
87
89
  ```
88
90
 
91
+ ### useHasParentContext
92
+
93
+ This helper hook will allow you to know if a component is wrapped by a context selector provider
94
+
95
+ ```tsx
96
+ const Foo = () => {
97
+ // An easy way to test if a context provider is wrapped around this component
98
+ // since it's more complicated to compare with a default context value
99
+ const isWrappedWithContext = useHasParentContext(CounterContext);
100
+
101
+ if (isWrappedWithContext) {
102
+ return <div>I am inside context selector provider</div>;
103
+ } else {
104
+ return <div>I can only use default context value</div>;
105
+ }
106
+ };
107
+ ```
108
+
89
109
  ## Technical memo
90
110
 
91
111
  React context by nature triggers propagation of component re-rendering if a value is changed. To avoid this, this library uses undocumented feature of `calculateChangedBits`. It then uses a subscription model to force update when a component needs to re-render.
@@ -32,4 +32,13 @@ export declare const createContext: <Value>(defaultValue: Value) => Context<Valu
32
32
  */
33
33
  export declare const useContextSelector: <Value, SelectedValue>(context: Context<Value>, selector: ContextSelector<Value, SelectedValue>) => SelectedValue;
34
34
 
35
+ /**
36
+ * Utility hook for contexts created by react-context-selector to determine if a parent context exists
37
+ * WARNING: This hook will not work for native React contexts
38
+ *
39
+ * @param context - context created by react-context-selector
40
+ * @returns whether the hook is wrapped by a parent context
41
+ */
42
+ export declare function useHasParentContext<Value>(context: Context<Value>): boolean;
43
+
35
44
  export { }
@@ -1,14 +1,14 @@
1
1
  import { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';
2
2
  import * as React from 'react';
3
3
  import { unstable_NormalPriority as NormalPriority, unstable_runWithPriority as runWithPriority } from 'scheduler';
4
- var createProvider = function (Original) {
5
- var Provider = function (props) {
4
+ const createProvider = (Original) => {
5
+ const Provider = props => {
6
6
  // Holds an actual "props.value"
7
- var valueRef = React.useRef(props.value);
7
+ const valueRef = React.useRef(props.value);
8
8
  // Used to sync context updates and avoid stale values, can be considered as render/effect counter of Provider.
9
- var versionRef = React.useRef(0);
9
+ const versionRef = React.useRef(0);
10
10
  // A stable object, is used to avoid context updates via mutation of its values.
11
- var contextValue = React.useRef();
11
+ const contextValue = React.useRef();
12
12
  if (!contextValue.current) {
13
13
  contextValue.current = {
14
14
  value: valueRef,
@@ -16,11 +16,11 @@ var createProvider = function (Original) {
16
16
  listeners: [],
17
17
  };
18
18
  }
19
- useIsomorphicLayoutEffect(function () {
19
+ useIsomorphicLayoutEffect(() => {
20
20
  valueRef.current = props.value;
21
21
  versionRef.current += 1;
22
- runWithPriority(NormalPriority, function () {
23
- contextValue.current.listeners.forEach(function (listener) {
22
+ runWithPriority(NormalPriority, () => {
23
+ contextValue.current.listeners.forEach(listener => {
24
24
  listener([versionRef.current, props.value]);
25
25
  });
26
26
  });
@@ -33,8 +33,8 @@ var createProvider = function (Original) {
33
33
  }
34
34
  return Provider;
35
35
  };
36
- export var createContext = function (defaultValue) {
37
- var context = React.createContext({
36
+ export const createContext = (defaultValue) => {
37
+ const context = React.createContext({
38
38
  value: { current: defaultValue },
39
39
  version: { current: -1 },
40
40
  listeners: [],
@@ -1 +1 @@
1
- {"version":3,"file":"createContext.js","sourceRoot":"../src/","sources":["createContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,uBAAuB,IAAI,cAAc,EAAE,wBAAwB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AA2D,CAAC;AACtE,CAAC,CAAC;AAEF,MAAM,CAAC,IAAM,aAAa,GAAG,UAAQ,YAAmB;IACtD,IAAM,OAAO,GAAG,KAAK,CAAC,aAAa,CAAsB;QACvD,KAAK,EAAE,EAAE,OAAO,EAAE,YAAY,EAAE;QAChC,OAAO,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC,EAAE;QACxB,SAAS,EAAE,EAAE;KACd,CAAC,CAAC;IAEH,OAAO,CAAC,QAAQ,GAAG,cAAc,CAAQ,OAAO,CAAC,QAAQ,CAAC,CAAC;IAE3D,gCAAgC;IAChC,OAAS,OAAsC,CAAC,QAAQ,CAAC;IAEzD,OAAQ,OAAqC,CAAC;AAChD,CAAC,CAAC","sourcesContent":["import { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\nimport * as React from 'react';\nimport { unstable_NormalPriority as NormalPriority, unstable_runWithPriority as runWithPriority } from 'scheduler';\n\nimport { Context, ContextValue } from './types';\n\nconst createProvider = <Value>(Original: React.Provider<ContextValue<Value>>) => {\n const Provider: React.FC<React.ProviderProps<Value>> = props => {\n // Holds an actual \"props.value\"\n const valueRef = React.useRef(props.value);\n // Used to sync context updates and avoid stale values, can be considered as render/effect counter of Provider.\n const versionRef = React.useRef(0);\n\n // A stable object, is used to avoid context updates via mutation of its values.\n const contextValue = React.useRef<ContextValue<Value>>();\n\n if (!contextValue.current) {\n contextValue.current = {\n value: valueRef,\n version: versionRef,\n listeners: [],\n };\n }\n\n useIsomorphicLayoutEffect(() => {\n valueRef.current = props.value;\n versionRef.current += 1;\n\n runWithPriority(NormalPriority, () => {\n (contextValue.current as ContextValue<Value>).listeners.forEach(listener => {\n listener([versionRef.current, props.value]);\n });\n });\n }, [props.value]);\n\n return React.createElement(Original, { value: contextValue.current }, props.children);\n };\n\n /* istanbul ignore else */\n if (process.env.NODE_ENV !== 'production') {\n Provider.displayName = 'ContextSelector.Provider';\n }\n\n return (Provider as unknown) as React.Provider<ContextValue<Value>>;\n};\n\nexport const createContext = <Value>(defaultValue: Value): Context<Value> => {\n const context = React.createContext<ContextValue<Value>>({\n value: { current: defaultValue },\n version: { current: -1 },\n listeners: [],\n });\n\n context.Provider = createProvider<Value>(context.Provider);\n\n // We don't support Consumer API\n delete ((context as unknown) as Context<Value>).Consumer;\n\n return (context as unknown) as Context<Value>;\n};\n"]}
1
+ {"version":3,"file":"createContext.js","sourceRoot":"","sources":["../src/createContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,uBAAuB,IAAI,cAAc,EAAE,wBAAwB,IAAI,eAAe,EAAE,MAAM,WAAW,CAAC;AAInH,MAAM,cAAc,GAAG,CAAQ,QAA6C,EAAE,EAAE;IAC9E,MAAM,QAAQ,GAAyC,KAAK,CAAC,EAAE;QAC7D,gCAAgC;QAChC,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC3C,+GAA+G;QAC/G,MAAM,UAAU,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QAEnC,gFAAgF;QAChF,MAAM,YAAY,GAAG,KAAK,CAAC,MAAM,EAAuB,CAAC;QAEzD,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE;YACzB,YAAY,CAAC,OAAO,GAAG;gBACrB,KAAK,EAAE,QAAQ;gBACf,OAAO,EAAE,UAAU;gBACnB,SAAS,EAAE,EAAE;aACd,CAAC;SACH;QAED,yBAAyB,CAAC,GAAG,EAAE;YAC7B,QAAQ,CAAC,OAAO,GAAG,KAAK,CAAC,KAAK,CAAC;YAC/B,UAAU,CAAC,OAAO,IAAI,CAAC,CAAC;YAExB,eAAe,CAAC,cAAc,EAAE,GAAG,EAAE;gBAClC,YAAY,CAAC,OAA+B,CAAC,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;oBACzE,QAAQ,CAAC,CAAC,UAAU,CAAC,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;gBAC9C,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;QAElB,OAAO,KAAK,CAAC,aAAa,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,YAAY,CAAC,OAAO,EAAE,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;IACxF,CAAC,CAAC;IAEF,0BAA0B;IAC1B,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE;QACzC,QAAQ,CAAC,WAAW,GAAG,0BAA0B,CAAC;KACnD;IAED,OAAQ,QAA2D,CAAC;AACtE,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG,CAAQ,YAAmB,EAAkB,EAAE;IAC1E,MAAM,OAAO,GAAG,KAAK,CAAC,aAAa,CAAsB;QACvD,KAAK,EAAE,EAAE,OAAO,EAAE,YAAY,EAAE;QAChC,OAAO,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC,EAAE;QACxB,SAAS,EAAE,EAAE;KACd,CAAC,CAAC;IAEH,OAAO,CAAC,QAAQ,GAAG,cAAc,CAAQ,OAAO,CAAC,QAAQ,CAAC,CAAC;IAE3D,gCAAgC;IAChC,OAAS,OAAsC,CAAC,QAAQ,CAAC;IAEzD,OAAQ,OAAqC,CAAC;AAChD,CAAC,CAAC"}
package/lib/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export { createContext } from './createContext';
2
2
  export { useContextSelector } from './useContextSelector';
3
+ export { useHasParentContext } from './useHasParentContext';
3
4
  export * from './types';
package/lib/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export { createContext } from './createContext';
2
2
  export { useContextSelector } from './useContextSelector';
3
+ export { useHasParentContext } from './useHasParentContext';
3
4
  export * from './types';
4
5
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"../src/","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,cAAc,SAAS,CAAC","sourcesContent":["export { createContext } from './createContext';\nexport { useContextSelector } from './useContextSelector';\nexport * from './types';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,cAAc,SAAS,CAAC"}
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.13.0"
8
+ "packageVersion": "7.18.1"
9
9
  }
10
10
  ]
11
11
  }
package/lib/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"../src/","sources":["types.ts"],"names":[],"mappings":"","sourcesContent":["import * as React from 'react';\n\nexport type Context<Value> = React.Context<Value> & {\n Provider: React.FC<React.ProviderProps<Value>>;\n Consumer: never;\n};\n\nexport type ContextSelector<Value, SelectedValue> = (value: Value) => SelectedValue;\n\nexport type ContextVersion = number;\n\nexport type ContextValue<Value> = {\n /** Holds a set of subscribers from components. */\n listeners: ((payload: readonly [ContextVersion, Value]) => void)[];\n\n /** Holds an actual value of React's context that will be propagated down for computations. */\n value: React.MutableRefObject<Value>;\n\n /** A version field is used to sync a context value and consumers. */\n version: React.MutableRefObject<ContextVersion>;\n};\n\nexport type ContextValues<Value> = ContextValue<Value> & {\n /** List of listners to publish changes */\n listeners: ((payload: readonly [ContextVersion, Record<string, Value>]) => void)[];\n};\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
@@ -5,11 +5,11 @@ import * as React from 'react';
5
5
  * It will only accept context created by `createContext`.
6
6
  * It will trigger re-render if only the selected value is referencially changed.
7
7
  */
8
- export var useContextSelector = function (context, selector) {
9
- var contextValue = React.useContext(context);
10
- var value = contextValue.value.current, version = contextValue.version.current, listeners = contextValue.listeners;
11
- var selected = selector(value);
12
- var _a = React.useReducer(function (prevState, payload) {
8
+ export const useContextSelector = (context, selector) => {
9
+ const contextValue = React.useContext(context);
10
+ const { value: { current: value }, version: { current: version }, listeners, } = contextValue;
11
+ const selected = selector(value);
12
+ const [state, dispatch] = React.useReducer((prevState, payload) => {
13
13
  if (!payload) {
14
14
  // early bail out when is dispatched during render
15
15
  return [value, selected];
@@ -24,7 +24,7 @@ export var useContextSelector = function (context, selector) {
24
24
  if (objectIs(prevState[0], payload[1])) {
25
25
  return prevState; // do not update
26
26
  }
27
- var nextSelected = selector(payload[1]);
27
+ const nextSelected = selector(payload[1]);
28
28
  if (objectIs(prevState[1], nextSelected)) {
29
29
  return prevState; // do not update
30
30
  }
@@ -35,16 +35,16 @@ export var useContextSelector = function (context, selector) {
35
35
  }
36
36
  // explicitly spread to enforce typing
37
37
  return [prevState[0], prevState[1]]; // schedule update
38
- }, [value, selected]), state = _a[0], dispatch = _a[1];
38
+ }, [value, selected]);
39
39
  if (!objectIs(state[1], selected)) {
40
40
  // schedule re-render
41
41
  // this is safe because it's self contained
42
42
  dispatch(undefined);
43
43
  }
44
- useIsomorphicLayoutEffect(function () {
44
+ useIsomorphicLayoutEffect(() => {
45
45
  listeners.push(dispatch);
46
- return function () {
47
- var index = listeners.indexOf(dispatch);
46
+ return () => {
47
+ const index = listeners.indexOf(dispatch);
48
48
  listeners.splice(index, 1);
49
49
  };
50
50
  }, [listeners]);
@@ -60,7 +60,7 @@ function is(x, y) {
60
60
  );
61
61
  }
62
62
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
63
- var objectIs =
63
+ const objectIs =
64
64
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
65
65
  // @ts-ignore fallback to native if it exists (not in IE11)
66
66
  typeof Object.is === 'function' ? Object.is : is;
@@ -1 +1 @@
1
- {"version":3,"file":"useContextSelector.js","sourceRoot":"../src/","sources":["useContextSelector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAa/B;;;;GAIG;AACH,MAAM,CAAC,IAAM,kBAAkB,GAAG,UAChC,OAAuB,EACvB,QAA+C;IAE/C,IAAM,YAAY,GAAG,KAAK,CAAC,UAAU,CAAE,OAAmD,CAAC,CAAC;IAGjF,IAAS,KAAK,GAGrB,YAAY,cAHS,EACH,OAAO,GAEzB,YAAY,gBAFa,EAC3B,SAAS,GACP,YAAY,UADL,CACM;IACjB,IAAM,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAE3B,IAAA,KAAoB,KAAK,CAAC,UAAU,CACxC,UACE,SAAmF,EACnF,OAEoC;QAEpC,IAAI,CAAC,OAAO,EAAE;YACZ,kDAAkD;YAClD,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAU,CAAC;SACnC;QAED,IAAI,OAAO,CAAC,CAAC,CAAC,IAAI,OAAO,EAAE;YACzB,IAAI,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,EAAE;gBACpC,OAAO,SAAS,CAAC,CAAC,WAAW;aAC9B;YAED,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAU,CAAC;SACnC;QAED,IAAI;YACF,IAAI,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE;gBACtC,OAAO,SAAS,CAAC,CAAC,gBAAgB;aACnC;YAED,IAAM,YAAY,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC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sCAAsC;KACzG,CAAC;AACJ,CAAC;AAED,8DAA8D;AAC9D,IAAM,QAAQ;AACZ,6DAA6D;AAC7D,2DAA2D;AAC3D,OAAO,MAAM,CAAC,EAAE,KAAK,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC","sourcesContent":["import { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\nimport * as React from 'react';\n\nimport { Context, ContextSelector, ContextValue, ContextVersion } from './types';\n\n/**\n * Narrowing React.Reducer type to be more easily usable below.\n * No need to export this as it's for internal reducer usage.\n */\ntype ContextReducer<Value, SelectedValue> = React.Reducer<\n readonly [Value, SelectedValue],\n undefined | readonly [ContextVersion, Value]\n>;\n\n/**\n * This hook returns context selected value by selector.\n * It will only accept context created by `createContext`.\n * It will trigger re-render if only the selected value is referencially changed.\n */\nexport const useContextSelector = <Value, SelectedValue>(\n context: Context<Value>,\n selector: ContextSelector<Value, SelectedValue>,\n): SelectedValue => {\n const contextValue = React.useContext((context as unknown) as Context<ContextValue<Value>>);\n\n const {\n value: { current: value },\n version: { current: version },\n listeners,\n } = contextValue;\n const selected = selector(value);\n\n const [state, dispatch] = React.useReducer<ContextReducer<Value, SelectedValue>>(\n (\n prevState: readonly [Value /* contextValue */, SelectedValue /* selector(value) */],\n payload:\n | undefined // undefined from render below\n | readonly [ContextVersion, Value], // from provider effect\n ): readonly [Value, SelectedValue] => {\n if (!payload) {\n // early bail out when is dispatched during render\n return [value, selected] as const;\n }\n\n if (payload[0] <= version) {\n if (objectIs(prevState[1], selected)) {\n return prevState; // bail out\n }\n\n return [value, selected] as const;\n }\n\n try {\n if (objectIs(prevState[0], payload[1])) {\n return prevState; // do not update\n }\n\n const nextSelected = selector(payload[1]);\n\n if (objectIs(prevState[1], nextSelected)) {\n return prevState; // do not update\n }\n\n return [payload[1], nextSelected] as const;\n } catch (e) {\n // ignored (stale props or some other reason)\n }\n\n // explicitly spread to enforce typing\n return [prevState[0], prevState[1]] as const; // schedule update\n },\n [value, selected] as const,\n );\n\n if (!objectIs(state[1], selected)) {\n // schedule re-render\n // this is safe because it's self contained\n dispatch(undefined);\n }\n\n useIsomorphicLayoutEffect(() => {\n listeners.push(dispatch);\n\n return () => {\n const index = listeners.indexOf(dispatch);\n listeners.splice(index, 1);\n };\n }, [listeners]);\n\n return state[1] as SelectedValue;\n};\n\n/**\n * inlined Object.is polyfill to avoid requiring consumers ship their own\n * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction is(x: any, y: any) {\n return (\n (x === y && (x !== 0 || 1 / x === 1 / y)) || (x !== x && y !== y) // eslint-disable-line no-self-compare\n );\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst objectIs: (x: any, y: any) => boolean =\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore fallback to native if it exists (not in IE11)\n typeof Object.is === 'function' ? Object.is : is;\n"]}
1
+ {"version":3,"file":"useContextSelector.js","sourceRoot":"","sources":["../src/useContextSelector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAa/B;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,OAAuB,EACvB,QAA+C,EAChC,EAAE;IACjB,MAAM,YAAY,GAAG,KAAK,CAAC,UAAU,CAAE,OAAmD,CAAC,CAAC;IAE5F,MAAM,EACJ,KAAK,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,EACzB,OAAO,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,EAC7B,SAAS,GACV,GAAG,YAAY,CAAC;IACjB,MAAM,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAEjC,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,KAAK,CAAC,UAAU,C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QAEzB,OAAO,GAAG,EAAE;YACV,MAAM,KAAK,GAAG,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;YAC1C,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QAC7B,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;IAEhB,OAAO,KAAK,CAAC,CAAC,CAAkB,CAAC;AACnC,CAAC,CAAC;AAEF;;;GAGG;AACH,8DAA8D;AAC9D,SAAS,EAAE,CAAC,CAAM,EAAE,CAAM;IACxB,OAAO,CACL,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,sCAAsC;KACzG,CAAC;AACJ,CAAC;AAED,8DAA8D;AAC9D,MAAM,QAAQ;AACZ,6DAA6D;AAC7D,2DAA2D;AAC3D,OAAO,MAAM,CAAC,EAAE,KAAK,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { Context } from './types';
2
+ /**
3
+ * Utility hook for contexts created by react-context-selector to determine if a parent context exists
4
+ * WARNING: This hook will not work for native React contexts
5
+ *
6
+ * @param context - context created by react-context-selector
7
+ * @returns whether the hook is wrapped by a parent context
8
+ */
9
+ export declare function useHasParentContext<Value>(context: Context<Value>): boolean;
@@ -0,0 +1,16 @@
1
+ import * as React from 'react';
2
+ /**
3
+ * Utility hook for contexts created by react-context-selector to determine if a parent context exists
4
+ * WARNING: This hook will not work for native React contexts
5
+ *
6
+ * @param context - context created by react-context-selector
7
+ * @returns whether the hook is wrapped by a parent context
8
+ */
9
+ export function useHasParentContext(context) {
10
+ const contextValue = React.useContext(context);
11
+ if (contextValue.version) {
12
+ return contextValue.version.current !== -1;
13
+ }
14
+ return false;
15
+ }
16
+ //# sourceMappingURL=useHasParentContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useHasParentContext.js","sourceRoot":"","sources":["../src/useHasParentContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CAAQ,OAAuB;IAChE,MAAM,YAAY,GAAG,KAAK,CAAC,UAAU,CAAE,OAAmD,CAAC,CAAC;IAE5F,IAAI,YAAY,CAAC,OAAO,EAAE;QACxB,OAAO,YAAY,CAAC,OAAO,CAAC,OAAO,KAAK,CAAC,CAAC,CAAC;KAC5C;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -1,17 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createContext = void 0;
4
- var react_utilities_1 = require("@fluentui/react-utilities");
5
- var React = require("react");
6
- var scheduler_1 = require("scheduler");
7
- var createProvider = function (Original) {
8
- var Provider = function (props) {
4
+ const react_utilities_1 = require("@fluentui/react-utilities");
5
+ const React = require("react");
6
+ const scheduler_1 = require("scheduler");
7
+ const createProvider = (Original) => {
8
+ const Provider = props => {
9
9
  // Holds an actual "props.value"
10
- var valueRef = React.useRef(props.value);
10
+ const valueRef = React.useRef(props.value);
11
11
  // Used to sync context updates and avoid stale values, can be considered as render/effect counter of Provider.
12
- var versionRef = React.useRef(0);
12
+ const versionRef = React.useRef(0);
13
13
  // A stable object, is used to avoid context updates via mutation of its values.
14
- var contextValue = React.useRef();
14
+ const contextValue = React.useRef();
15
15
  if (!contextValue.current) {
16
16
  contextValue.current = {
17
17
  value: valueRef,
@@ -19,11 +19,11 @@ var createProvider = function (Original) {
19
19
  listeners: [],
20
20
  };
21
21
  }
22
- react_utilities_1.useIsomorphicLayoutEffect(function () {
22
+ react_utilities_1.useIsomorphicLayoutEffect(() => {
23
23
  valueRef.current = props.value;
24
24
  versionRef.current += 1;
25
- scheduler_1.unstable_runWithPriority(scheduler_1.unstable_NormalPriority, function () {
26
- contextValue.current.listeners.forEach(function (listener) {
25
+ scheduler_1.unstable_runWithPriority(scheduler_1.unstable_NormalPriority, () => {
26
+ contextValue.current.listeners.forEach(listener => {
27
27
  listener([versionRef.current, props.value]);
28
28
  });
29
29
  });
@@ -36,8 +36,8 @@ var createProvider = function (Original) {
36
36
  }
37
37
  return Provider;
38
38
  };
39
- var createContext = function (defaultValue) {
40
- var context = React.createContext({
39
+ const createContext = (defaultValue) => {
40
+ const context = React.createContext({
41
41
  value: { current: defaultValue },
42
42
  version: { current: -1 },
43
43
  listeners: [],