@fluentui/react-context-selector 9.0.0-alpha.7 → 9.0.0-beta.2

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 (40) hide show
  1. package/CHANGELOG.json +716 -1
  2. package/CHANGELOG.md +322 -2
  3. package/README.md +20 -0
  4. package/dist/react-context-selector.d.ts +9 -0
  5. package/lib/createContext.js.map +1 -1
  6. package/lib/index.d.ts +1 -0
  7. package/lib/index.js +1 -0
  8. package/lib/index.js.map +1 -1
  9. package/lib/tsdoc-metadata.json +1 -1
  10. package/lib/types.js.map +1 -1
  11. package/lib/useContextSelector.js.map +1 -1
  12. package/lib/useHasParentContext.d.ts +9 -0
  13. package/lib/useHasParentContext.js +16 -0
  14. package/lib/useHasParentContext.js.map +1 -0
  15. package/lib-commonjs/createContext.js.map +1 -1
  16. package/lib-commonjs/index.d.ts +1 -0
  17. package/lib-commonjs/index.js +3 -1
  18. package/lib-commonjs/index.js.map +1 -1
  19. package/lib-commonjs/types.js.map +1 -1
  20. package/lib-commonjs/useContextSelector.js.map +1 -1
  21. package/lib-commonjs/useHasParentContext.d.ts +9 -0
  22. package/lib-commonjs/useHasParentContext.js +20 -0
  23. package/lib-commonjs/useHasParentContext.js.map +1 -0
  24. package/package.json +7 -7
  25. package/config/api-extractor.json +0 -3
  26. package/config/tests.js +0 -1
  27. package/etc/react-context-selector.api.md +0 -42
  28. package/just.config.ts +0 -3
  29. package/lib-amd/createContext.d.ts +0 -2
  30. package/lib-amd/createContext.js +0 -48
  31. package/lib-amd/createContext.js.map +0 -1
  32. package/lib-amd/index.d.ts +0 -3
  33. package/lib-amd/index.js +0 -9
  34. package/lib-amd/index.js.map +0 -1
  35. package/lib-amd/types.d.ts +0 -19
  36. package/lib-amd/types.js +0 -5
  37. package/lib-amd/types.js.map +0 -1
  38. package/lib-amd/useContextSelector.d.ts +0 -7
  39. package/lib-amd/useContextSelector.js +0 -71
  40. package/lib-amd/useContextSelector.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,12 +1,332 @@
1
1
  # Change Log - @fluentui/react-context-selector
2
2
 
3
- This log was last generated on Wed, 19 May 2021 07:30:20 GMT and should not be manually modified.
3
+ This log was last generated on Wed, 27 Oct 2021 12:12:32 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## [9.0.0-beta.2](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-beta.2)
8
+
9
+ Wed, 27 Oct 2021 12:12:32 GMT
10
+ [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)
11
+
12
+ ### Changes
13
+
14
+ - Bump @fluentui/react-utilities to v9.0.0-beta.2 ([PR #20353](https://github.com/microsoft/fluentui/pull/20353) by beachball)
15
+
16
+ ## [9.0.0-beta.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-beta.1)
17
+
18
+ Wed, 06 Oct 2021 10:37:22 GMT
19
+ [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)
20
+
21
+ ### Changes
22
+
23
+ - Bump all v9 components to beta prerelease tag ([PR #20106](https://github.com/microsoft/fluentui/pull/20106) by lingfangao@hotmail.com)
24
+ - Bump @fluentui/react-utilities to v9.0.0-beta.1 ([PR #20106](https://github.com/microsoft/fluentui/pull/20106) by beachball)
25
+
26
+ ## [9.0.0-alpha.39](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.39)
27
+
28
+ Tue, 05 Oct 2021 09:28:07 GMT
29
+ [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)
30
+
31
+ ### Changes
32
+
33
+ - Bump @fluentui/react-utilities to v9.0.0-alpha.56 ([PR #20081](https://github.com/microsoft/fluentui/pull/20081) by beachball)
34
+
35
+ ## [9.0.0-alpha.38](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.38)
36
+
37
+ Fri, 01 Oct 2021 14:13:08 GMT
38
+ [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)
39
+
40
+ ### Changes
41
+
42
+ - Bump v9 prerelease versions to rerelease ([PR #20069](https://github.com/microsoft/fluentui/pull/20069) by lingfangao@hotmail.com)
43
+ - Bump @fluentui/react-utilities to v9.0.0-alpha.55 ([PR #20069](https://github.com/microsoft/fluentui/pull/20069) by beachball)
44
+
45
+ ## [9.0.0-alpha.36](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.36)
46
+
47
+ Mon, 27 Sep 2021 08:06:00 GMT
48
+ [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)
49
+
50
+ ### Changes
51
+
52
+ - Bump @fluentui/react-utilities to v9.0.0-alpha.53 ([PR #19981](https://github.com/microsoft/fluentui/pull/19981) by beachball)
53
+
54
+ ## [9.0.0-alpha.35](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.35)
55
+
56
+ Fri, 24 Sep 2021 09:17:17 GMT
57
+ [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)
58
+
59
+ ### Changes
60
+
61
+ - Bump @fluentui/react-utilities to v9.0.0-alpha.52 ([PR #19950](https://github.com/microsoft/fluentui/pull/19950) by beachball)
62
+
63
+ ## [9.0.0-alpha.34](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.34)
64
+
65
+ Thu, 23 Sep 2021 08:21:34 GMT
66
+ [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)
67
+
68
+ ### Changes
69
+
70
+ - Bump @fluentui/react-utilities to v9.0.0-alpha.51 ([commit](https://github.com/microsoft/fluentui/commit/95682da34c48813f7658032ae490d21d2f363b90) by beachball)
71
+
72
+ ## [9.0.0-alpha.33](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.33)
73
+
74
+ Wed, 22 Sep 2021 10:10:07 GMT
75
+ [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)
76
+
77
+ ### Changes
78
+
79
+ - Bump @fluentui/react-utilities to v9.0.0-alpha.50 ([commit](https://github.com/microsoft/fluentui/commit/bc3f1ec72fc7784a558b0dd6598ee0662f4649c1) by beachball)
80
+
81
+ ## [9.0.0-alpha.32](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.32)
82
+
83
+ Fri, 17 Sep 2021 07:35:26 GMT
84
+ [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)
85
+
86
+ ### Changes
87
+
88
+ - 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)
89
+
90
+ ## [9.0.0-alpha.31](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.31)
91
+
92
+ Thu, 16 Sep 2021 07:38:39 GMT
93
+ [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)
94
+
95
+ ### Changes
96
+
97
+ - Bump @fluentui/react-context-selector to v9.0.0-alpha.31 ([PR #19815](https://github.com/microsoft/fluentui/pull/19815) by behowell@microsoft.com)
98
+
99
+ ## [9.0.0-alpha.30](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.30)
100
+
101
+ Tue, 14 Sep 2021 20:09:02 GMT
102
+ [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)
103
+
104
+ ### Changes
105
+
106
+ - Bump @fluentui/react-context-selector to v9.0.0-alpha.30 ([PR #19155](https://github.com/microsoft/fluentui/pull/19155) by bsunderhus@microsoft.com)
107
+
108
+ ## [9.0.0-alpha.29](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.29)
109
+
110
+ Fri, 10 Sep 2021 16:31:53 GMT
111
+ [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)
112
+
113
+ ### Changes
114
+
115
+ - 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)
116
+ - Bump @fluentui/react-context-selector to v9.0.0-alpha.29 ([PR #19748](https://github.com/microsoft/fluentui/pull/19748) by lingfangao@hotmail.com)
117
+
118
+ ## [9.0.0-alpha.28](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.28)
119
+
120
+ Fri, 10 Sep 2021 07:39:51 GMT
121
+ [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)
122
+
123
+ ### Changes
124
+
125
+ - Bump @fluentui/react-utilities to v9.0.0-alpha.45 ([PR #19642](https://github.com/microsoft/fluentui/pull/19642) by behowell@microsoft.com)
126
+
127
+ ## [9.0.0-alpha.27](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.27)
128
+
129
+ Mon, 06 Sep 2021 07:34:53 GMT
130
+ [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)
131
+
132
+ ### Changes
133
+
134
+ - Bump @fluentui/react-utilities to v9.0.0-alpha.44 ([PR #19640](https://github.com/microsoft/fluentui/pull/19640) by lingfangao@hotmail.com)
135
+
136
+ ## [9.0.0-alpha.26](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.26)
137
+
138
+ Wed, 01 Sep 2021 07:39:56 GMT
139
+ [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)
140
+
141
+ ### Changes
142
+
143
+ - Bump @fluentui/react-utilities to v9.0.0-alpha.43 ([PR #19483](https://github.com/microsoft/fluentui/pull/19483) by bsunderhus@microsoft.com)
144
+
145
+ ## [9.0.0-alpha.25](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.25)
146
+
147
+ Tue, 31 Aug 2021 07:37:47 GMT
148
+ [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)
149
+
150
+ ### Changes
151
+
152
+ - Bump @fluentui/react-utilities to v9.0.0-alpha.42 ([PR #19556](https://github.com/microsoft/fluentui/pull/19556) by lingfan.gao@microsoft.com)
153
+
154
+ ## [9.0.0-alpha.24](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.24)
155
+
156
+ Fri, 20 Aug 2021 07:37:28 GMT
157
+ [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)
158
+
159
+ ### Changes
160
+
161
+ - Update .npmignore ([PR #19441](https://github.com/microsoft/fluentui/pull/19441) by elcraig@microsoft.com)
162
+
163
+ ## [9.0.0-alpha.23](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.23)
164
+
165
+ Thu, 19 Aug 2021 07:41:35 GMT
166
+ [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)
167
+
168
+ ### Changes
169
+
170
+ - Bump @fluentui/react-utilities to v9.0.0-alpha.39 ([PR #19273](https://github.com/microsoft/fluentui/pull/19273) by bsunderhus@microsoft.com)
171
+
172
+ ## [9.0.0-alpha.22](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.22)
173
+
174
+ Fri, 06 Aug 2021 07:35:14 GMT
175
+ [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)
176
+
177
+ ### Changes
178
+
179
+ - Bump @fluentui/react-utilities to v9.0.0-alpha.38 ([PR #19189](https://github.com/microsoft/fluentui/pull/19189) by bsunderhus@microsoft.com)
180
+
181
+ ## [9.0.0-alpha.21](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.21)
182
+
183
+ Tue, 03 Aug 2021 07:39:30 GMT
184
+ [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)
185
+
186
+ ### Patches
187
+
188
+ - Bump @fluentui/eslint-plugin to v1.3.3 ([PR #19169](https://github.com/microsoft/fluentui/pull/19169) by behowell@microsoft.com)
189
+ - Bump @fluentui/scripts to v1.0.0 ([PR #19169](https://github.com/microsoft/fluentui/pull/19169) by behowell@microsoft.com)
190
+
191
+ ### Changes
192
+
193
+ - Bump @fluentui/react-utilities to v9.0.0-alpha.37 ([PR #19169](https://github.com/microsoft/fluentui/pull/19169) by behowell@microsoft.com)
194
+
195
+ ## [9.0.0-alpha.20](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.20)
196
+
197
+ Mon, 02 Aug 2021 07:36:20 GMT
198
+ [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)
199
+
200
+ ### Changes
201
+
202
+ - Bump @fluentui/react-utilities to v9.0.0-alpha.36 ([PR #19204](https://github.com/microsoft/fluentui/pull/19204) by lingfan.gao@microsoft.com)
203
+
204
+ ## [9.0.0-alpha.19](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.19)
205
+
206
+ Fri, 23 Jul 2021 07:38:19 GMT
207
+ [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)
208
+
209
+ ### Changes
210
+
211
+ - Bump @fluentui/react-utilities to v9.0.0-alpha.35 ([PR #18610](https://github.com/microsoft/fluentui/pull/18610) by behowell@microsoft.com)
212
+
213
+ ## [9.0.0-alpha.18](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.18)
214
+
215
+ Thu, 22 Jul 2021 07:36:55 GMT
216
+ [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)
217
+
218
+ ### Changes
219
+
220
+ - Bump @fluentui/react-utilities to v9.0.0-alpha.34 ([PR #19023](https://github.com/microsoft/fluentui/pull/19023) by behowell@microsoft.com)
221
+
222
+ ## [9.0.0-alpha.17](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.17)
223
+
224
+ Thu, 15 Jul 2021 07:36:18 GMT
225
+ [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)
226
+
227
+ ### Changes
228
+
229
+ - 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)
230
+
231
+ ## [9.0.0-alpha.16](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.16)
232
+
233
+ Fri, 09 Jul 2021 07:39:31 GMT
234
+ [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)
235
+
236
+ ### Patches
237
+
238
+ - Bump @fluentui/eslint-plugin to v1.3.2 ([PR #18808](https://github.com/microsoft/fluentui/pull/18808) by martinhochel@microsoft.com)
239
+ - Bump @fluentui/scripts to v1.0.0 ([PR #18808](https://github.com/microsoft/fluentui/pull/18808) by martinhochel@microsoft.com)
240
+
241
+ ### Changes
242
+
243
+ - Bump @fluentui/react-utilities to v9.0.0-alpha.32 ([PR #18808](https://github.com/microsoft/fluentui/pull/18808) by martinhochel@microsoft.com)
244
+
245
+ ## [9.0.0-alpha.15](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.15)
246
+
247
+ Fri, 02 Jul 2021 23:15:55 GMT
248
+ [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)
249
+
250
+ ### Changes
251
+
252
+ - Bump @fluentui/react-utilities to v9.0.0-alpha.31 ([PR #18721](https://github.com/microsoft/fluentui/pull/18721) by bsunderhus@microsoft.com)
253
+
254
+ ## [9.0.0-alpha.14](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.14)
255
+
256
+ Fri, 02 Jul 2021 07:37:06 GMT
257
+ [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)
258
+
259
+ ### Changes
260
+
261
+ - Bump @fluentui/react-utilities to v9.0.0-alpha.30 ([PR #18796](https://github.com/microsoft/fluentui/pull/18796) by bsunderhus@microsoft.com)
262
+
263
+ ## [9.0.0-alpha.13](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.13)
264
+
265
+ Tue, 15 Jun 2021 07:40:20 GMT
266
+ [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)
267
+
268
+ ### Changes
269
+
270
+ - Bump @fluentui/react-utilities to v9.0.0-alpha.29 ([PR #18521](https://github.com/microsoft/fluentui/pull/18521) by behowell@microsoft.com)
271
+
272
+ ## [9.0.0-alpha.12](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.12)
273
+
274
+ Mon, 07 Jun 2021 07:38:15 GMT
275
+ [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)
276
+
277
+ ### Patches
278
+
279
+ - Bump @fluentui/eslint-plugin to v1.3.1 ([PR #18437](https://github.com/microsoft/fluentui/pull/18437) by martinhochel@microsoft.com)
280
+ - Bump @fluentui/scripts to v1.0.0 ([PR #18437](https://github.com/microsoft/fluentui/pull/18437) by martinhochel@microsoft.com)
281
+
282
+ ### Changes
283
+
284
+ - Bump @fluentui/react-utilities to v9.0.0-alpha.28 ([PR #18437](https://github.com/microsoft/fluentui/pull/18437) by martinhochel@microsoft.com)
285
+
286
+ ## [9.0.0-alpha.11](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.11)
287
+
288
+ Fri, 04 Jun 2021 07:37:23 GMT
289
+ [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)
290
+
291
+ ### Changes
292
+
293
+ - Bump @fluentui/react-utilities to v9.0.0-alpha.27 ([PR #18168](https://github.com/microsoft/fluentui/pull/18168) by Humberto.Morimoto@microsoft.com)
294
+
295
+ ## [9.0.0-alpha.10](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.10)
296
+
297
+ Wed, 26 May 2021 07:35:43 GMT
298
+ [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)
299
+
300
+ ### Changes
301
+
302
+ - Bump @fluentui/react-utilities to v9.0.0-alpha.25 ([PR #18323](https://github.com/microsoft/fluentui/pull/18323) by lingfan.gao@microsoft.com)
303
+
304
+ ## [9.0.0-alpha.9](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.9)
305
+
306
+ Fri, 21 May 2021 07:34:54 GMT
307
+ [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)
308
+
309
+ ### Changes
310
+
311
+ - Bump @fluentui/react-utilities to v9.0.0-alpha.24 ([PR #18259](https://github.com/microsoft/fluentui/pull/18259) by behowell@microsoft.com)
312
+
313
+ ## [9.0.0-alpha.8](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.8)
314
+
315
+ Thu, 20 May 2021 07:41:54 GMT
316
+ [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)
317
+
318
+ ### Patches
319
+
320
+ - Bump @fluentui/eslint-plugin to v1.3.0 ([PR #18024](https://github.com/microsoft/fluentui/pull/18024) by elcraig@microsoft.com)
321
+ - Bump @fluentui/scripts to v1.0.0 ([PR #18024](https://github.com/microsoft/fluentui/pull/18024) by elcraig@microsoft.com)
322
+
323
+ ### Changes
324
+
325
+ - Bump @fluentui/react-utilities to v9.0.0-alpha.23 ([PR #18024](https://github.com/microsoft/fluentui/pull/18024) by elcraig@microsoft.com)
326
+
7
327
  ## [9.0.0-alpha.7](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.0.0-alpha.7)
8
328
 
9
- Wed, 19 May 2021 07:30:20 GMT
329
+ Wed, 19 May 2021 07:34:20 GMT
10
330
  [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.0.0-alpha.6..@fluentui/react-context-selector_v9.0.0-alpha.7)
11
331
 
12
332
  ### Changes
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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,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,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,IAAM,cAAc,GAAG,UAAQ,QAA6C;IAC1E,IAAM,QAAQ,GAAyC,UAAA,KAAK;QAC1D,gCAAgC;QAChC,IAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC3C,+GAA+G;QAC/G,IAAM,UAAU,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QAEnC,gFAAgF;QAChF,IAAM,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;YACxB,QAAQ,CAAC,OAAO,GAAG,KAAK,CAAC,KAAK,CAAC;YAC/B,UAAU,CAAC,OAAO,IAAI,CAAC,CAAC;YAExB,eAAe,CAAC,cAAc,EAAE;gBAC7B,YAAY,CAAC,OAA+B,CAAC,SAAS,CAAC,OAAO,CAAC,UAAA,QAAQ;oBACtE,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,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"}
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":""}
@@ -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;gB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CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,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,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,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IAAI,CAAC,QAAQ,CAAC,CAAC;QAEzB,OAAO;YACL,IAAM,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,IAAM,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
+ var 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,IAAM,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 +1 @@
1
- {"version":3,"file":"createContext.js","sourceRoot":"../src/","sources":["createContext.ts"],"names":[],"mappings":";;;AAAA,6DAAsE;AACtE,6BAA+B;AAC/B,uCAAmH;AAInH,IAAM,cAAc,GAAG,UAAQ,QAA6C;IAC1E,IAAM,QAAQ,GAAyC,UAAA,KAAK;QAC1D,gCAAgC;QAChC,IAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC3C,+GAA+G;QAC/G,IAAM,UAAU,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QAEnC,gFAAgF;QAChF,IAAM,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,2CAAyB,CAAC;YACxB,QAAQ,CAAC,OAAO,GAAG,KAAK,CAAC,KAAK,CAAC;YAC/B,UAAU,CAAC,OAAO,IAAI,CAAC,CAAC;YAExB,oCAAe,CAAC,mCAAc,EAAE;gBAC7B,YAAY,CAAC,OAA+B,CAAC,SAAS,CAAC,OAAO,CAAC,UAAA,QAAQ;oBACtE,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;AAEK,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;AAbW,QAAA,aAAa,iBAaxB","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,6DAAsE;AACtE,6BAA+B;AAC/B,uCAAmH;AAInH,IAAM,cAAc,GAAG,UAAQ,QAA6C;IAC1E,IAAM,QAAQ,GAAyC,UAAA,KAAK;QAC1D,gCAAgC;QAChC,IAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC3C,+GAA+G;QAC/G,IAAM,UAAU,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QAEnC,gFAAgF;QAChF,IAAM,YAAY,GAAG,KAAK,CAAC,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,gCAAgC;IAChC,OAAS,OAAsC,CAAC,QAAQ,CAAC;IAEzD,OAAQ,OAAqC,CAAC;AAChD,CAAC,CAAC;AAbW,QAAA,aAAa,iBAaxB"}
@@ -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';
@@ -1,10 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useContextSelector = exports.createContext = void 0;
3
+ exports.useHasParentContext = exports.useContextSelector = exports.createContext = void 0;
4
4
  var tslib_1 = require("tslib");
5
5
  var createContext_1 = require("./createContext");
6
6
  Object.defineProperty(exports, "createContext", { enumerable: true, get: function () { return createContext_1.createContext; } });
7
7
  var useContextSelector_1 = require("./useContextSelector");
8
8
  Object.defineProperty(exports, "useContextSelector", { enumerable: true, get: function () { return useContextSelector_1.useContextSelector; } });
9
+ var useHasParentContext_1 = require("./useHasParentContext");
10
+ Object.defineProperty(exports, "useHasParentContext", { enumerable: true, get: function () { return useHasParentContext_1.useHasParentContext; } });
9
11
  tslib_1.__exportStar(require("./types"), exports);
10
12
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"../src/","sources":["index.ts"],"names":[],"mappings":";;;;AAAA,iDAAgD;AAAvC,8GAAA,aAAa,OAAA;AACtB,2DAA0D;AAAjD,wHAAA,kBAAkB,OAAA;AAC3B,kDAAwB","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,iDAAgD;AAAvC,8GAAA,aAAa,OAAA;AACtB,2DAA0D;AAAjD,wHAAA,kBAAkB,OAAA;AAC3B,6DAA4D;AAAnD,0HAAA,mBAAmB,OAAA;AAC5B,kDAAwB"}
@@ -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":""}
@@ -1 +1 @@
1
- {"version":3,"file":"useContextSelector.js","sourceRoot":"../src/","sources":["useContextSelector.ts"],"names":[],"mappings":";;;AAAA,6DAAsE;AACtE,6BAA+B;AAa/B;;;;GAIG;AACI,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,Q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AAC,SAAS,CAAC,CAAC,CAAC;IAEhB,OAAO,KAAK,CAAC,CAAC,CAAkB,CAAC;AACnC,CAAC,CAAC;AAvEW,QAAA,kBAAkB,sBAuE7B;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,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,6DAAsE;AACtE,6BAA+B;AAa/B;;;;GAIG;AACI,IAAM,kBAAkB,GAAG,UAChC,OAAuB,EACvB,QAA+C;IAE/C,IAAM,YAAY,GAAG,KAAK,CAAC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EAAE,QAAQ,QAwCrB,CAAC;IAEF,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,EAAE;QACjC,qBAAqB;QACrB,2CAA2C;QAC3C,QAAQ,CAAC,SAAS,CAAC,CAAC;KACrB;IAED,2CAAyB,CAAC;QACxB,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAEzB,OAAO;YACL,IAAM,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;AAvEW,QAAA,kBAAkB,sBAuE7B;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,IAAM,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,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useHasParentContext = void 0;
4
+ var React = require("react");
5
+ /**
6
+ * Utility hook for contexts created by react-context-selector to determine if a parent context exists
7
+ * WARNING: This hook will not work for native React contexts
8
+ *
9
+ * @param context - context created by react-context-selector
10
+ * @returns whether the hook is wrapped by a parent context
11
+ */
12
+ function useHasParentContext(context) {
13
+ var contextValue = React.useContext(context);
14
+ if (contextValue.version) {
15
+ return contextValue.version.current !== -1;
16
+ }
17
+ return false;
18
+ }
19
+ exports.useHasParentContext = useHasParentContext;
20
+ //# sourceMappingURL=useHasParentContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useHasParentContext.js","sourceRoot":"","sources":["../src/useHasParentContext.ts"],"names":[],"mappings":";;;AAAA,6BAA+B;AAG/B;;;;;;GAMG;AACH,SAAgB,mBAAmB,CAAQ,OAAuB;IAChE,IAAM,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;AARD,kDAQC"}