@qyu/reactcmp-dropdown 1.2.0 → 2.0.0

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 (84) hide show
  1. package/README.md +173 -75
  2. package/build/bundle/entry/index.js +1266 -398
  3. package/build/declaration/component/button/element/view.d.ts +8 -5
  4. package/build/declaration/component/button/element/virtual.d.ts +9 -0
  5. package/build/declaration/component/container/element/view.d.ts +14 -23
  6. package/build/declaration/component/container/element/virtual.d.ts +13 -0
  7. package/build/declaration/component/content/element/view.d.ts +11 -0
  8. package/build/declaration/component/ctx-state/element/config.d.ts +3 -0
  9. package/build/declaration/component/ctx-state/element/content.d.ts +3 -0
  10. package/build/declaration/component/ctx-state/element/open.d.ts +2 -5
  11. package/build/declaration/component/ctx-state/element/refs.d.ts +3 -0
  12. package/build/declaration/component/ctx-state/hook/init/config.d.ts +8 -0
  13. package/build/declaration/component/ctx-state/hook/init/content.d.ts +6 -0
  14. package/build/declaration/component/ctx-state/hook/init/open.d.ts +7 -0
  15. package/build/declaration/component/ctx-state/hook/init/refs.d.ts +5 -0
  16. package/build/declaration/component/ctx-state/hook/view/config.d.ts +1 -0
  17. package/build/declaration/component/ctx-state/hook/view/content.d.ts +1 -0
  18. package/build/declaration/component/ctx-state/hook/view/open.d.ts +1 -0
  19. package/build/declaration/component/ctx-state/hook/view/refs.d.ts +1 -0
  20. package/build/declaration/component/ctx-state/type/state.d.ts +40 -6
  21. package/build/declaration/component/list-abs/element/view.d.ts +23 -36
  22. package/build/declaration/component/list-fix/element/view.d.ts +24 -38
  23. package/build/declaration/component/list-portal/element/view.d.ts +29 -0
  24. package/build/declaration/hook/closeevt/root.d.ts +8 -0
  25. package/build/declaration/hook/closeevt/root_infer.d.ts +3 -0
  26. package/build/declaration/hook/closeevt/shard.d.ts +9 -0
  27. package/build/declaration/hook/closeevt/shard_infer.d.ts +3 -0
  28. package/build/declaration/hook/ddnparts/list.d.ts +6 -0
  29. package/build/declaration/hook/ddnparts/list_infer.d.ts +3 -0
  30. package/build/declaration/hook/ddnparts/root.d.ts +8 -0
  31. package/build/declaration/hook/ddnparts/root_infer.d.ts +3 -0
  32. package/build/declaration/hook/ddnparts/shard.d.ts +9 -0
  33. package/build/declaration/hook/ddnparts/shard_infer.d.ts +3 -0
  34. package/build/declaration/hook/focus/capture.d.ts +16 -0
  35. package/build/declaration/hook/focus/capture_infer.d.ts +3 -0
  36. package/build/declaration/hook/listpos/api/absolute.d.ts +15 -0
  37. package/build/declaration/hook/listpos/api/fixed.d.ts +18 -0
  38. package/build/declaration/hook/listpos/api/type/api.d.ts +13 -0
  39. package/build/declaration/hook/listpos/api/type/position.d.ts +6 -0
  40. package/build/declaration/hook/listpos/api/type/reverse.d.ts +4 -0
  41. package/build/declaration/hook/listpos/api/type/size.d.ts +4 -0
  42. package/build/declaration/hook/listpos/rearrange/index.d.ts +10 -0
  43. package/build/declaration/hook/listpos/rearrange/type/config.d.ts +7 -0
  44. package/build/declaration/hook/open/view.d.ts +6 -0
  45. package/build/declaration/hook/open/view_infer.d.ts +3 -0
  46. package/build/declaration/hook/ref/merge.d.ts +2 -0
  47. package/build/declaration/hook/ref/o.d.ts +3 -0
  48. package/build/declaration/index.d.ts +58 -3
  49. package/build/declaration/type/fnref.d.ts +4 -0
  50. package/build/declaration/util/clname/merge.d.ts +1 -0
  51. package/build/declaration/util/closeevt/type/config.d.ts +11 -0
  52. package/build/declaration/util/cssprops/new/position.d.ts +3 -0
  53. package/build/declaration/util/cssprops/new/size.d.ts +9 -0
  54. package/build/declaration/util/focus/config/type/config.d.ts +6 -0
  55. package/build/declaration/util/prop/align/new/index.d.ts +2 -0
  56. package/build/declaration/util/prop/align/new/reversed.d.ts +2 -0
  57. package/build/declaration/util/prop/align/type/prop.d.ts +2 -0
  58. package/build/declaration/util/prop/clmap/def/container.d.ts +6 -0
  59. package/build/declaration/util/prop/clmap/def/content.d.ts +8 -0
  60. package/build/declaration/util/prop/clmap/def/listabs.d.ts +15 -0
  61. package/build/declaration/util/prop/clmap/def/listfix.d.ts +16 -0
  62. package/build/declaration/util/prop/clmap/new/index.d.ts +2 -0
  63. package/build/declaration/util/prop/clmap/type/prop.d.ts +4 -0
  64. package/build/declaration/util/prop/direction/new/index.d.ts +2 -0
  65. package/build/declaration/util/prop/direction/type/prop.d.ts +2 -0
  66. package/build/declaration/util/prop/justify/new/index.d.ts +2 -0
  67. package/build/declaration/util/prop/justify/new/reversed.d.ts +2 -0
  68. package/build/declaration/util/prop/justify/type/prop.d.ts +2 -0
  69. package/build/declaration/util/prop/portal/new/index.d.ts +2 -0
  70. package/build/declaration/util/prop/portal/type/prop.d.ts +2 -0
  71. package/build/declaration/util/ref/use.d.ts +2 -0
  72. package/build/style/index.css +132 -0
  73. package/build/style/index.css.d.ts +21 -0
  74. package/package.json +6 -9
  75. package/build/declaration/component/container/hook/useDropdownCloseEvents.d.ts +0 -15
  76. package/build/declaration/type/params.d.ts +0 -6
  77. package/build/declaration/util/cl.d.ts +0 -1
  78. package/build/declaration/util/nprop/index.d.ts +0 -5
  79. package/build/declaration/util/stylemap/new/remap.d.ts +0 -2
  80. package/build/declaration/util/stylemap/type/StyleMap.d.ts +0 -3
  81. package/build/style/index.global.css +0 -110
  82. package/build/style/index.global.css.d.ts +0 -21
  83. package/build/style/index.module.css +0 -110
  84. package/build/style/index.module.css.d.ts +0 -20
@@ -1,69 +1,224 @@
1
1
  import * as r from 'react';
2
- import { jsx } from 'react/jsx-runtime';
2
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
3
3
  import * as rdom from 'react-dom';
4
4
 
5
5
  const CmpCtxState_Open = r.createContext(null);
6
6
 
7
- const CmpButton = props => {
8
- const ctxstate = r.useContext(CmpCtxState_Open);
9
- if (!ctxstate) {
10
- throw new Error(`Using DropdownStateOpen dependend component outside of DropdownStateOpen Context`);
7
+ const CmpCtxState_Refs = r.createContext(null);
8
+
9
+ const CmpCtxState_Content = r.createContext(null);
10
+
11
+ const CmpCtxState_Config = r.createContext(null);
12
+
13
+ const useCtxStateOpen = function () {
14
+ const ctxstate_open = r.useContext(CmpCtxState_Open);
15
+ if (!ctxstate_open) {
16
+ throw new Error(`Using DDN dependend component outside of DDNOpen Context`);
11
17
  }
12
- const event_click = r.useCallback(() => {
13
- ctxstate.open_set(t => !t);
14
- }, []);
15
- return jsx("button", { onClick: event_click, className: props.className, children: props.children });
18
+ return ctxstate_open;
16
19
  };
17
20
 
18
- const useDropdownCloseEvents = function (params) {
19
- const nconfig_blur = params.config?.blur ?? true;
20
- const nconfig_click = params.config?.click ?? true;
21
- const nconfig_scroll = params.config?.scroll ?? true;
22
- const nconfig_resize = params.config?.resize ?? true;
23
- const nconfig_escape = params.config?.escape ?? true;
24
- r.useEffect(() => {
25
- const container = params.ref();
26
- if (params.open && container) {
27
- const controller = new AbortController();
28
- if (nconfig_blur) {
29
- container.addEventListener("focusout", ev => {
30
- if (!(ev.relatedTarget instanceof Element) || !container.contains(ev.relatedTarget)) {
31
- params.open_set(false);
21
+ const useCtxStateRefs = function () {
22
+ const ctxstate_open = r.useContext(CmpCtxState_Refs);
23
+ if (!ctxstate_open) {
24
+ throw new Error(`Using DDN dependend component outside of DDNRefs Context`);
25
+ }
26
+ return ctxstate_open;
27
+ };
28
+
29
+ const useCtxStateContent = function () {
30
+ const ctxstate_content = r.useContext(CmpCtxState_Content);
31
+ if (!ctxstate_content) {
32
+ throw new Error(`Using DDN dependend component outside of DDNContent Context`);
33
+ }
34
+ return ctxstate_content;
35
+ };
36
+
37
+ const useCtxStateConfig = function () {
38
+ const ctxstate_open = r.useContext(CmpCtxState_Config);
39
+ if (!ctxstate_open) {
40
+ throw new Error(`Using DDN dependend component outside of DDNConfig Context`);
41
+ }
42
+ return ctxstate_open;
43
+ };
44
+
45
+ const useCtxStateInitOpen = function (params) {
46
+ const ctxstate_open = r.useContext(CmpCtxState_Open);
47
+ const [l_open, l_open_set] = r.useState(false);
48
+ const open = params.open ?? l_open;
49
+ const open_set = params.open_set ?? l_open_set;
50
+ return r.useMemo(() => {
51
+ return {
52
+ open_local: open,
53
+ open_inherited: open && (ctxstate_open?.open_inherited ?? true),
54
+ open_set
55
+ };
56
+ }, [open, open_set, ctxstate_open?.open_inherited]);
57
+ };
58
+
59
+ const useCascade = function () {
60
+ const [cascade, cascade_set] = r.useState(0);
61
+ const ctxstate_refs = r.useContext(CmpCtxState_Refs);
62
+ return [
63
+ cascade,
64
+ r.useMemo(() => {
65
+ return {
66
+ increment: () => {
67
+ cascade_set(n => n + 1);
68
+ ctxstate_refs?.cascade_api?.increment();
69
+ },
70
+ decrement: () => {
71
+ cascade_set(n => n - 1);
72
+ ctxstate_refs?.cascade_api?.decrement();
73
+ },
74
+ };
75
+ }, [ctxstate_refs?.cascade_api])
76
+ ];
77
+ };
78
+ const useRegister = function () {
79
+ const ctxstate_refs = r.useContext(CmpCtxState_Refs);
80
+ const l_register_local = r.useMemo(() => new Set(), []);
81
+ const l_register_down = r.useMemo(() => new Set(), []);
82
+ return r.useMemo(() => {
83
+ return {
84
+ add_own: ref => {
85
+ l_register_local.add(ref);
86
+ ctxstate_refs?.register.add_down(ref);
87
+ },
88
+ delete_own: ref => {
89
+ l_register_local.delete(ref);
90
+ ctxstate_refs?.register.delete_down(ref);
91
+ },
92
+ add_down: ref => {
93
+ l_register_down.add(ref);
94
+ ctxstate_refs?.register.add_down(ref);
95
+ },
96
+ delete_down: ref => {
97
+ l_register_down.delete(ref);
98
+ ctxstate_refs?.register.delete_down(ref);
99
+ },
100
+ it_full: {
101
+ [Symbol.iterator]: function* () {
102
+ if (ctxstate_refs) {
103
+ yield* ctxstate_refs.register.it_up;
104
+ yield* ctxstate_refs.register.it_context;
32
105
  }
33
- }, { signal: controller.signal });
34
- }
35
- if (nconfig_click) {
36
- document.addEventListener("click", ev => {
37
- const path = ev.composedPath();
38
- if (!container || !path.includes(container)) {
39
- params.open_set(false);
106
+ yield* l_register_local;
107
+ yield* l_register_down;
108
+ }
109
+ },
110
+ it_local: {
111
+ [Symbol.iterator]: function* () {
112
+ yield* l_register_local;
113
+ }
114
+ },
115
+ it_up: {
116
+ [Symbol.iterator]: function* () {
117
+ if (ctxstate_refs) {
118
+ yield* ctxstate_refs.register.it_up;
119
+ yield* ctxstate_refs.register.it_context;
40
120
  }
41
- }, { signal: controller.signal });
121
+ }
122
+ },
123
+ it_down: {
124
+ [Symbol.iterator]: function* () {
125
+ yield* l_register_down;
126
+ }
127
+ },
128
+ it_context: {
129
+ [Symbol.iterator]: function* () {
130
+ yield* l_register_local;
131
+ yield* l_register_down;
132
+ }
42
133
  }
43
- if (nconfig_escape) {
44
- document.addEventListener("keydown", ev => {
45
- if (!ev.defaultPrevented && ev.key.toLowerCase() === "escape") {
46
- params.open_set(false);
47
- ev.preventDefault();
134
+ };
135
+ }, [ctxstate_refs?.register, l_register_local, l_register_down]);
136
+ };
137
+ const useCtxStateInitRefs = function (params) {
138
+ const register = useRegister();
139
+ const [cascade, cascade_api] = useCascade();
140
+ const [rootref, rootref_set] = r.useState(() => new Set());
141
+ const shardevt_scroll = r.useMemo(() => new Set(), []);
142
+ return r.useMemo(() => {
143
+ return {
144
+ register,
145
+ container_real: params.container_real,
146
+ shardevt_scroll,
147
+ rootref,
148
+ rootref_set,
149
+ cascade,
150
+ cascade_api,
151
+ };
152
+ }, [params.container_real, register, rootref, shardevt_scroll, cascade, cascade_api]);
153
+ };
154
+
155
+ const useCtxStateInitContent = function (params) {
156
+ return r.useMemo(() => {
157
+ return {
158
+ ref_content: params.ref_content,
159
+ };
160
+ }, [params.ref_content]);
161
+ };
162
+
163
+ const useCtxStateInitConfig = function (params) {
164
+ const nprop_focus = r.useMemo(() => params.focus ?? {}, [params.focus]);
165
+ const nprop_closeevt = r.useMemo(() => params.closeevt ?? {}, [params.closeevt]);
166
+ return r.useMemo(() => {
167
+ return {
168
+ focus: nprop_focus,
169
+ closeevt: nprop_closeevt,
170
+ };
171
+ }, [nprop_closeevt, nprop_focus]);
172
+ };
173
+
174
+ const useDDNRoot = function (params) {
175
+ const { ctxstate_refs } = params;
176
+ r.useLayoutEffect(() => {
177
+ if (params.active) {
178
+ ctxstate_refs.rootref_set(old_rootref => {
179
+ const now_rootref = new Set(old_rootref);
180
+ now_rootref.add(params.ref);
181
+ return now_rootref;
182
+ });
183
+ return () => {
184
+ ctxstate_refs.rootref_set(old_rootref => {
185
+ const now_rootref = new Set(old_rootref);
186
+ now_rootref.delete(params.ref);
187
+ return now_rootref;
188
+ });
189
+ };
190
+ }
191
+ }, [ctxstate_refs.rootref_set, params.ref, params.active]);
192
+ };
193
+
194
+ const useDDNRootInfer = function (params) {
195
+ const ctxstate_refs = useCtxStateRefs();
196
+ useDDNRoot({
197
+ ...params,
198
+ ctxstate_refs,
199
+ });
200
+ };
201
+
202
+ const useCloseEvtShard = function (params) {
203
+ const { ctxstate_refs, ctxstate_open, ctxstate_config, } = params;
204
+ const nconfig_scroll = ctxstate_config.closeevt.scroll ?? true;
205
+ r.useEffect(() => {
206
+ if (params.active) {
207
+ const element = params.ref();
208
+ const controller = new AbortController();
209
+ if (element) {
210
+ let parent = element.parentElement;
211
+ const scroll_handler = (event) => {
212
+ if (nconfig_scroll) {
213
+ ctxstate_open.open_set(false);
48
214
  }
49
- }, { signal: controller.signal });
50
- }
51
- if (nconfig_resize) {
52
- window.addEventListener("resize", () => {
53
- params.open_set(false);
54
- }, { signal: controller.signal });
55
- }
56
- if (nconfig_scroll) {
57
- let parent = container.parentElement;
215
+ ctxstate_refs.shardevt_scroll.forEach(cb => cb(event));
216
+ };
58
217
  while (parent) {
59
- parent.addEventListener("scroll", () => {
60
- params.open_set(false);
61
- }, { signal: controller.signal });
218
+ parent.addEventListener("scroll", scroll_handler, { signal: controller.signal });
62
219
  parent = parent.parentElement;
63
220
  }
64
- document.addEventListener("scroll", () => {
65
- params.open_set(false);
66
- }, { signal: controller.signal });
221
+ document.addEventListener("scroll", scroll_handler, { signal: controller.signal });
67
222
  }
68
223
  return () => {
69
224
  controller.abort();
@@ -71,126 +226,192 @@ const useDropdownCloseEvents = function (params) {
71
226
  }
72
227
  }, [
73
228
  params.ref,
74
- params.open,
75
- params.open_set,
76
- nconfig_click,
229
+ params.active,
230
+ ctxstate_open.open_set,
77
231
  nconfig_scroll,
78
- nconfig_resize,
79
- nconfig_escape
232
+ ctxstate_refs.shardevt_scroll,
80
233
  ]);
81
234
  };
82
235
 
83
- const cl = function (...clnames) {
84
- let result = [];
85
- for (const clname of clnames) {
86
- if (clname) {
87
- result.push(clname);
236
+ const useDDNShard = function (params) {
237
+ const { ctxstate_open, ctxstate_refs, ctxstate_config } = params;
238
+ useCloseEvtShard({
239
+ ref: params.ref,
240
+ active: params.isolated || !ctxstate_refs.container_real,
241
+ ctxstate_open,
242
+ ctxstate_refs,
243
+ ctxstate_config,
244
+ });
245
+ r.useLayoutEffect(() => {
246
+ if (params.isolated || !ctxstate_refs.container_real) {
247
+ ctxstate_refs.register.add_own(params.ref);
248
+ return () => {
249
+ ctxstate_refs.register.delete_own(params.ref);
250
+ };
88
251
  }
89
- }
90
- return result.join(" ");
252
+ }, [ctxstate_refs.register, ctxstate_refs.container_real, params.isolated, params.ref]);
91
253
  };
92
254
 
93
- const stylemap_new_remap = function (def, remap) {
94
- const result = {};
95
- for (const clname of Object.keys(def)) {
96
- const remaped = remap[clname];
97
- if (remaped !== undefined) {
98
- result[clname] = remaped;
99
- continue;
255
+ const useDDNShardInfer = function (params) {
256
+ const ctxstate_open = useCtxStateOpen();
257
+ const ctxstate_refs = useCtxStateRefs();
258
+ const ctxstate_config = useCtxStateConfig();
259
+ useDDNShard({
260
+ ...params,
261
+ ctxstate_refs,
262
+ ctxstate_open,
263
+ ctxstate_config,
264
+ });
265
+ };
266
+
267
+ const ref_use = function (ref, value) {
268
+ if (ref) {
269
+ if (typeof ref === "object") {
270
+ ref.current = value;
100
271
  }
101
- {
102
- result[clname] = clname;
272
+ else {
273
+ ref(value);
103
274
  }
104
275
  }
105
- return result;
106
276
  };
107
277
 
108
- const stylemap$2 = {
109
- container: "container"
278
+ const useRefMerge = function (...refs) {
279
+ return r.useCallback((value) => {
280
+ for (const ref of refs) {
281
+ ref_use(ref, value);
282
+ }
283
+ }, refs);
284
+ };
285
+
286
+ const render_view_default$5 = function (props) {
287
+ return jsx("button", { ...props });
110
288
  };
111
- const CmpContainer = r.memo(r.forwardRef((props, ref) => {
112
- const nprop_style = r.useMemo(() => (props.stylemodule ? stylemap_new_remap(stylemap$2, props.stylemodule) : stylemap$2), [props.stylemodule]);
289
+ const CmpButton = r.memo(r.forwardRef((props, f_ref) => {
290
+ const nprop_render_view = props.render_view ?? render_view_default$5;
291
+ const ctxstate_refs = useCtxStateRefs();
292
+ const ctxstate_open = useCtxStateOpen();
113
293
  const l_ref = r.useRef(null);
114
- const [open, open_set] = r.useState(false);
115
- const l_open = props.open ?? open;
116
- const l_open_set = props.open_set ?? open_set;
117
- const ctxstate = r.useMemo(() => {
118
- return {
119
- open: l_open,
120
- ref: l_ref,
121
- open_set: l_open_set,
122
- };
123
- }, [l_open, l_open_set]);
124
- const mref = r.useMemo(() => {
125
- return (element) => {
126
- l_ref.current = element;
127
- if (ref) {
128
- if (typeof ref === "object") {
129
- ref.current = element;
130
- }
131
- else {
132
- ref(element);
133
- }
134
- }
135
- };
136
- }, [ref]);
137
- useDropdownCloseEvents({
138
- config: props.closeevents,
294
+ const event_click = r.useCallback(() => {
295
+ ctxstate_open.open_set(t => !t);
296
+ }, []);
297
+ useDDNShardInfer({
298
+ isolated: false,
139
299
  ref: r.useCallback(() => l_ref.current, []),
140
- open: ctxstate.open,
141
- open_set: ctxstate.open_set,
142
300
  });
143
- return jsx("div", { ref: mref, className: cl("__qyuddn", props.className, nprop_style.container), children: jsx(CmpCtxState_Open.Provider, { value: ctxstate, children: props.children }) });
301
+ useDDNRootInfer({
302
+ ref: r.useCallback(() => l_ref.current, []),
303
+ active: props.isroot ?? !ctxstate_refs.container_real,
304
+ });
305
+ const ref = useRefMerge(l_ref, f_ref);
306
+ return nprop_render_view({
307
+ ref,
308
+ onClick: event_click,
309
+ disabled: props.disabled,
310
+ children: props.children,
311
+ className: props.className,
312
+ });
144
313
  }));
145
314
 
146
- const nprop_align_new = function (raw) {
147
- if (!raw) {
148
- return "start";
149
- }
150
- if (raw === true) {
151
- return "end";
152
- }
153
- return raw;
315
+ const CmpButtonVirtual = r.memo(props => {
316
+ const { target: ref_target } = props;
317
+ const ctxstate_refs = useCtxStateRefs();
318
+ useDDNShardInfer({
319
+ ref: ref_target,
320
+ isolated: false,
321
+ });
322
+ useDDNRootInfer({
323
+ ref: ref_target,
324
+ active: props.isroot ?? !ctxstate_refs.container_real,
325
+ });
326
+ return props.children;
327
+ });
328
+
329
+ const useDDNList = function (params) {
330
+ const { ctxstate_refs } = params;
331
+ r.useEffect(() => {
332
+ if (params.visible) {
333
+ ctxstate_refs.cascade_api.increment();
334
+ return () => {
335
+ ctxstate_refs.cascade_api.decrement();
336
+ };
337
+ }
338
+ }, [params.visible, ctxstate_refs.cascade_api]);
154
339
  };
155
- const nprop_justify_new = function (raw) {
156
- if (!raw) {
157
- return "end";
158
- }
159
- if (raw === true) {
160
- return "start";
161
- }
162
- return raw;
340
+
341
+ const useDDNListInfer = function (params) {
342
+ const ctxstate_refs = useCtxStateRefs();
343
+ useDDNList({
344
+ ...params,
345
+ ctxstate_refs,
346
+ });
163
347
  };
164
- const nprop_direction_new = function (raw) {
165
- if (!raw) {
166
- return "ver";
167
- }
168
- if (raw === true) {
169
- return "hor";
348
+
349
+ const refs_unpack$1 = function* (src) {
350
+ for (const ref of src) {
351
+ const element = ref();
352
+ if (element) {
353
+ yield element;
354
+ }
170
355
  }
171
- return raw;
172
356
  };
173
- const nprop_portal_new = function (portal) {
174
- if (typeof portal === "string") {
175
- return document.getElementById(portal) ?? null;
176
- }
177
- if (portal) {
178
- return portal;
357
+ const element_inside = function (element, shards) {
358
+ for (const ref of shards) {
359
+ if (ref === element || ref.contains(element)) {
360
+ return true;
361
+ }
179
362
  }
180
- return null;
363
+ return false;
181
364
  };
365
+ function useFocusCapture(params) {
366
+ const { ctxstate_config, ctxstate_refs } = params;
367
+ const nprop_move = ctxstate_config.focus.capture ?? true;
368
+ const nprop_restore = ctxstate_config.focus.capture ?? true;
369
+ const nprop_capture_options = r.useMemo(() => {
370
+ return ctxstate_config.focus.capture_options ?? {
371
+ preventScroll: true,
372
+ };
373
+ }, [ctxstate_config.focus.capture_options]);
374
+ const nprop_restore_options = r.useMemo(() => {
375
+ return ctxstate_config.focus.restore_options ?? {
376
+ preventScroll: true,
377
+ };
378
+ }, [ctxstate_config.focus.restore_options]);
379
+ const ref_restorecapture = r.useRef(null);
380
+ r.useLayoutEffect(() => {
381
+ if (params.open) {
382
+ if (document.activeElement instanceof HTMLElement) {
383
+ ref_restorecapture.current = document.activeElement;
384
+ }
385
+ if (nprop_move) {
386
+ params.ref_target()?.focus(nprop_capture_options);
387
+ }
388
+ }
389
+ else {
390
+ const active = document.activeElement;
391
+ const restorecapture = ref_restorecapture.current;
392
+ {
393
+ ref_restorecapture.current = null;
394
+ }
395
+ if (nprop_restore && restorecapture && active instanceof HTMLElement) {
396
+ const active_inside = element_inside(active, refs_unpack$1(ctxstate_refs.register.it_context));
397
+ if (active_inside) {
398
+ restorecapture.focus(nprop_restore_options);
399
+ }
400
+ }
401
+ }
402
+ }, [params.open]);
403
+ }
182
404
 
183
- const stylemap$1 = {
184
- listfix: "listfix",
185
- listfix_open: "listfix_open",
186
- listfix_justify_start: "listfix_justify_start",
187
- listfix_justify_end: "listfix_justify_end",
188
- listfix_align_start: "listfix_align_start",
189
- listfix_align_end: "listfix_align_end",
190
- listfix_align_center: "listfix_align_center",
191
- listfix_vertical: "listfix_vertical",
192
- listfix_horizontal: "listfix_horizontal",
405
+ const useFocusCaptureInfer = function (params) {
406
+ const ctxstate_refs = useCtxStateRefs();
407
+ const ctxstate_config = useCtxStateConfig();
408
+ useFocusCapture({
409
+ ...params,
410
+ ctxstate_refs,
411
+ ctxstate_config,
412
+ });
193
413
  };
414
+
194
415
  const normalize_justify$1 = function (params) {
195
416
  let axis_main;
196
417
  switch (params.direction) {
@@ -229,27 +450,15 @@ const normalize_justify$1 = function (params) {
229
450
  break;
230
451
  }
231
452
  }
232
- if (freespace_direct >= axis_main.list_size) {
233
- params.reverse_justify_set(false);
234
- axis_main.space_set(null);
235
- flow_direct.position_set(position_direct);
236
- flow_reverse.position_set(null);
237
- }
238
- else if (freespace_reverse >= axis_main.list_size) {
239
- params.reverse_justify_set(true);
240
- axis_main.space_set(null);
241
- flow_direct.position_set(null);
242
- flow_reverse.position_set(position_reverse);
243
- }
244
- else if (freespace_direct >= freespace_reverse) {
245
- params.reverse_justify_set(false);
246
- axis_main.space_set(freespace_direct);
453
+ if (freespace_direct >= axis_main.list_size || freespace_direct >= freespace_reverse) {
454
+ params.reverse_set(false);
455
+ axis_main.size_set(Math.min(freespace_direct, axis_main.list_size));
247
456
  flow_direct.position_set(position_direct);
248
457
  flow_reverse.position_set(null);
249
458
  }
250
459
  else {
251
- params.reverse_justify_set(true);
252
- axis_main.space_set(freespace_reverse);
460
+ params.reverse_set(true);
461
+ axis_main.size_set(Math.min(freespace_reverse, axis_main.list_size));
253
462
  flow_direct.position_set(null);
254
463
  flow_reverse.position_set(position_reverse);
255
464
  }
@@ -266,13 +475,37 @@ const normalize_align$1 = function (params) {
266
475
  break;
267
476
  }
268
477
  }
269
- axis_main.space_set(null);
270
478
  switch (params.align) {
271
479
  case "center": {
272
- const offset = (axis_main.list_size - axis_main.container_size) / 2;
273
- params.reverse_align_set(false);
274
- axis_main.flow_reverse.position_set(null);
275
- axis_main.flow_direct.position_set(Math.max(0, axis_main.container_pos - offset));
480
+ if (axis_main.list_size >= axis_main.screen_size) {
481
+ params.reverse_set(false);
482
+ axis_main.size_set(axis_main.screen_size);
483
+ axis_main.flow_direct.position_set(0);
484
+ axis_main.flow_reverse.position_set(null);
485
+ }
486
+ else {
487
+ const point = axis_main.container_pos + axis_main.container_size / 2;
488
+ const freespace_reverse = point;
489
+ const freespace_direct = axis_main.screen_size - point;
490
+ if (axis_main.list_size >= freespace_reverse) {
491
+ params.reverse_set(false);
492
+ axis_main.flow_direct.position_set(0);
493
+ axis_main.flow_reverse.position_set(null);
494
+ axis_main.size_set(axis_main.list_size);
495
+ }
496
+ else if (axis_main.list_size >= freespace_direct) {
497
+ params.reverse_set(true);
498
+ axis_main.flow_reverse.position_set(0);
499
+ axis_main.flow_direct.position_set(null);
500
+ axis_main.size_set(axis_main.list_size);
501
+ }
502
+ else {
503
+ params.reverse_set(false);
504
+ axis_main.flow_direct.position_set(point - axis_main.list_size / 2);
505
+ axis_main.flow_reverse.position_set(null);
506
+ axis_main.size_set(axis_main.list_size);
507
+ }
508
+ }
276
509
  break;
277
510
  }
278
511
  case "start": {
@@ -286,12 +519,13 @@ const normalize_align$1 = function (params) {
286
519
  - (axis_main.container_pos + axis_main.container_size)
287
520
  - Math.max(0, axis_main.list_size - freespace_reverse)));
288
521
  if (freespace_direct >= axis_main.list_size || freespace_direct >= freespace_reverse) {
289
- params.reverse_align_set(false);
290
- flow_reverse.position_set(null);
522
+ params.reverse_set(false);
523
+ axis_main.size_set(Math.min(freespace_direct, axis_main.list_size));
291
524
  flow_direct.position_set(position_direct);
292
525
  }
293
526
  else {
294
- params.reverse_align_set(true);
527
+ params.reverse_set(true);
528
+ axis_main.size_set(Math.min(freespace_reverse, axis_main.list_size));
295
529
  flow_direct.position_set(null);
296
530
  flow_reverse.position_set(position_reverse);
297
531
  }
@@ -308,12 +542,14 @@ const normalize_align$1 = function (params) {
308
542
  const position_reverse = Math.max(0, (+axis_main.container_pos
309
543
  - Math.max(0, axis_main.list_size - freespace_reverse)));
310
544
  if (freespace_direct >= axis_main.list_size || freespace_direct >= freespace_reverse) {
311
- params.reverse_align_set(false);
545
+ params.reverse_set(false);
546
+ axis_main.size_set(Math.min(freespace_direct, axis_main.list_size));
312
547
  flow_reverse.position_set(null);
313
548
  flow_direct.position_set(position_direct);
314
549
  }
315
550
  else {
316
- params.reverse_align_set(true);
551
+ params.reverse_set(true);
552
+ axis_main.size_set(Math.min(freespace_reverse, axis_main.list_size));
317
553
  flow_direct.position_set(null);
318
554
  flow_reverse.position_set(position_reverse);
319
555
  }
@@ -321,142 +557,417 @@ const normalize_align$1 = function (params) {
321
557
  }
322
558
  }
323
559
  };
324
- const CmpListFix = r.memo(r.forwardRef((props, ref) => {
325
- const nprop_gap = props.gap ?? 0;
326
- const nprop_lazy = props.lazy ?? false;
327
- const nprop_align = nprop_align_new(props.align);
328
- const nprop_portal = nprop_portal_new(props.portal);
329
- const nprop_justify = nprop_justify_new(props.justify);
330
- const nprop_direction = nprop_direction_new(props.direction);
331
- const nprop_style = r.useMemo(() => (props.stylemodule ? stylemap_new_remap(stylemap$1, props.stylemodule) : stylemap$1), [props.stylemodule]);
332
- const ctxstate = r.useContext(CmpCtxState_Open);
333
- if (!ctxstate) {
334
- throw new Error(`Using DDN dependend component outside of DDN Context`);
335
- }
336
- const l_ref = r.useRef(null);
337
- const [visible, visible_set] = r.useState(false);
338
- const [revalign, revalign_set] = r.useState(false);
339
- const [revjustify, revjustify_set] = r.useState(false);
340
- const [maxheight, maxheight_set] = r.useState(null);
341
- const [maxwidth, maxwidth_set] = r.useState(null);
560
+ const useListPosApiFixed = function (params) {
561
+ const ctxstate_refs = useCtxStateRefs();
562
+ const [align_reverse, align_reverse_set] = r.useState(false);
563
+ const [justify_reverse, justify_reverse_set] = r.useState(false);
564
+ let [width, width_set] = r.useState(null);
565
+ let [height, height_set] = r.useState(null);
342
566
  const [top, top_set] = r.useState(null);
343
567
  const [left, left_set] = r.useState(null);
344
568
  const [right, right_set] = r.useState(null);
345
569
  const [bottom, bottom_set] = r.useState(null);
570
+ return {
571
+ reverse: r.useMemo(() => ({
572
+ align: align_reverse,
573
+ justify: justify_reverse,
574
+ }), [align_reverse, justify_reverse]),
575
+ size: r.useMemo(() => ({
576
+ width: width,
577
+ height: height,
578
+ }), [width, height]),
579
+ position: r.useMemo(() => ({
580
+ top,
581
+ left,
582
+ right,
583
+ bottom,
584
+ }), [top, left, right, bottom]),
585
+ api: r.useMemo(() => ({
586
+ clear: () => {
587
+ align_reverse_set(false);
588
+ justify_reverse_set(false);
589
+ top_set(null);
590
+ left_set(null);
591
+ right_set(null);
592
+ bottom_set(null);
593
+ },
594
+ rearrange: config => {
595
+ const list = params.ref_list();
596
+ const content = params.ref_content();
597
+ const container = [...ctxstate_refs.rootref].map(ref => ref()).find(el => el !== null);
598
+ if (list && container && content) {
599
+ if (params.clmap_content._tracking) {
600
+ content.classList.add(params.clmap_content._tracking);
601
+ }
602
+ const container_rect = container.getBoundingClientRect();
603
+ const axis_main = {
604
+ list_size: content.offsetHeight,
605
+ screen_size: document.documentElement.clientHeight,
606
+ container_pos: container_rect.y,
607
+ container_size: container_rect.height,
608
+ size_set: height_set,
609
+ flow_direct: {
610
+ position_set: top_set
611
+ },
612
+ flow_reverse: {
613
+ position_set: bottom_set
614
+ },
615
+ };
616
+ const axis_cross = {
617
+ list_size: content.offsetWidth,
618
+ screen_size: document.documentElement.clientWidth,
619
+ container_pos: container_rect.x,
620
+ container_size: container_rect.width,
621
+ size_set: width_set,
622
+ flow_direct: {
623
+ position_set: left_set
624
+ },
625
+ flow_reverse: {
626
+ position_set: right_set
627
+ },
628
+ };
629
+ normalize_justify$1({
630
+ axis_main,
631
+ axis_cross,
632
+ gap: config.gap,
633
+ justify: config.justify,
634
+ direction: config.direction,
635
+ reverse_set: justify_reverse_set,
636
+ });
637
+ normalize_align$1({
638
+ axis_main,
639
+ axis_cross,
640
+ align: config.align,
641
+ direction: config.direction,
642
+ reverse_set: align_reverse_set,
643
+ });
644
+ if (params.clmap_content._tracking) {
645
+ content.classList.remove(params.clmap_content._tracking);
646
+ }
647
+ }
648
+ },
649
+ }), [ctxstate_refs.rootref, params.ref_list, params.ref_content])
650
+ };
651
+ };
652
+
653
+ const useListPosRearrange = function (params) {
654
+ const nprop_rearrange_open = params.rearrange_config?.open ?? true;
655
+ const nprop_rearrange_scroll = params.rearrange_config?.scroll ?? true;
656
+ const nprop_rearrange_resize = params.rearrange_config?.resize ?? true;
657
+ const nprop_rearrange_polling = params.rearrange_config?.polling ?? false;
658
+ const ctxstate_refs = useCtxStateRefs();
659
+ const rearrange = r.useCallback(() => {
660
+ params.api.rearrange(params.api_config);
661
+ }, [
662
+ params.api,
663
+ params.api_config.gap,
664
+ params.api_config.align,
665
+ params.api_config.justify,
666
+ params.api_config.direction,
667
+ ]);
346
668
  r.useLayoutEffect(() => {
347
- const list = l_ref.current;
348
- const container = ctxstate.ref.current;
349
- if (list && container && ctxstate.open) {
350
- const container_rect = container.getBoundingClientRect();
351
- const axis_main = {
352
- list_size: list.offsetHeight,
353
- space_set: maxheight_set,
354
- screen_size: document.documentElement.clientHeight,
355
- container_pos: container_rect.y,
356
- container_size: container_rect.height,
357
- flow_direct: {
358
- position_set: top_set
359
- },
360
- flow_reverse: {
361
- position_set: bottom_set
362
- },
669
+ if (params.rearrange_config?.deps && params.open) {
670
+ rearrange();
671
+ }
672
+ }, [...params.rearrange_config?.deps ?? []]);
673
+ r.useLayoutEffect(() => {
674
+ if (nprop_rearrange_open && params.open) {
675
+ rearrange();
676
+ }
677
+ }, [rearrange, params.open]);
678
+ r.useLayoutEffect(() => {
679
+ if (nprop_rearrange_resize && params.active) {
680
+ document.addEventListener("resize", rearrange);
681
+ return () => {
682
+ document.addEventListener("resize", rearrange);
363
683
  };
364
- const axis_cross = {
365
- list_size: list.offsetWidth,
366
- space_set: maxwidth_set,
367
- screen_size: document.documentElement.clientWidth,
368
- container_pos: container_rect.x,
369
- container_size: container_rect.width,
370
- flow_direct: {
371
- position_set: left_set
372
- },
373
- flow_reverse: {
374
- position_set: right_set
375
- },
684
+ }
685
+ }, [rearrange, params.active, nprop_rearrange_resize]);
686
+ r.useLayoutEffect(() => {
687
+ if (nprop_rearrange_scroll && params.active) {
688
+ ctxstate_refs.shardevt_scroll.add(rearrange);
689
+ return () => {
690
+ ctxstate_refs.shardevt_scroll.delete(rearrange);
376
691
  };
377
- normalize_justify$1({
378
- axis_main,
379
- axis_cross,
380
- gap: nprop_gap,
381
- justify: nprop_justify,
382
- direction: nprop_direction,
383
- reverse_align_set: revalign_set,
384
- reverse_justify_set: revjustify_set,
385
- });
386
- normalize_align$1({
387
- axis_main,
388
- axis_cross,
389
- align: nprop_align,
390
- direction: nprop_direction,
391
- reverse_align_set: revalign_set,
392
- reverse_justify_set: revjustify_set,
393
- });
394
692
  }
395
- }, [ctxstate.open, ctxstate.ref, nprop_gap, nprop_align, nprop_justify, nprop_direction]);
396
- const mref = r.useMemo(() => {
397
- return (element) => {
398
- l_ref.current = element;
399
- if (ref) {
400
- if (typeof ref === "object") {
401
- ref.current = element;
402
- }
403
- else {
404
- ref(element);
405
- }
693
+ }, [rearrange, params.active, nprop_rearrange_scroll]);
694
+ r.useLayoutEffect(() => {
695
+ if (nprop_rearrange_polling && params.active) {
696
+ let frame_id;
697
+ const frame_cb = () => {
698
+ rearrange();
699
+ frame_id = requestAnimationFrame(frame_cb);
700
+ };
701
+ requestAnimationFrame(frame_cb);
702
+ return () => {
703
+ cancelAnimationFrame(frame_id);
704
+ };
705
+ }
706
+ }, [rearrange, params.active, nprop_rearrange_polling, ctxstate_refs]);
707
+ };
708
+
709
+ const useOpen = function (params) {
710
+ const { ctxstate_open, ctxstate_refs } = params;
711
+ return r.useMemo(() => {
712
+ return ctxstate_open.open_inherited || ctxstate_refs.cascade > 1;
713
+ }, [ctxstate_open.open_inherited, ctxstate_refs.cascade]);
714
+ };
715
+
716
+ const useOpenInfer = function (params) {
717
+ const ctxstate_refs = useCtxStateRefs();
718
+ const ctxstate_open = useCtxStateOpen();
719
+ return useOpen({
720
+ ...params,
721
+ ctxstate_open,
722
+ ctxstate_refs,
723
+ });
724
+ };
725
+
726
+ const useRefO = function (ref) {
727
+ return r.useCallback(() => ref.current, [ref]);
728
+ };
729
+
730
+ const cl = function (...names) {
731
+ let result = [];
732
+ for (const name of names) {
733
+ if (name) {
734
+ result.push(name);
735
+ }
736
+ }
737
+ if (result.length === 0) {
738
+ return undefined;
739
+ }
740
+ return result.join(" ");
741
+ };
742
+
743
+ const cssprops_new_position = function (params) {
744
+ const result = {};
745
+ if (params.top !== null) {
746
+ result.top = `${params.top}px`;
747
+ }
748
+ if (params.left !== null) {
749
+ result.left = `${params.left}px`;
750
+ }
751
+ if (params.right !== null) {
752
+ result.right = `${params.right}px`;
753
+ }
754
+ if (params.bottom !== null) {
755
+ result.bottom = `${params.bottom}px`;
756
+ }
757
+ return result;
758
+ };
759
+
760
+ const cssprops_new_size = function (params) {
761
+ const result = {};
762
+ switch (params.direction) {
763
+ case "hor": {
764
+ if (params.open) {
765
+ result.width = params.size.width ?? 1;
406
766
  }
407
- };
408
- }, [ref]);
767
+ else {
768
+ result.width = 1;
769
+ }
770
+ if (params.size.height) {
771
+ result.height = params.size.height;
772
+ }
773
+ break;
774
+ }
775
+ case "ver": {
776
+ if (params.open) {
777
+ result.height = params.size.height ?? 1;
778
+ }
779
+ else {
780
+ result.height = 1;
781
+ }
782
+ if (params.size.width) {
783
+ result.width = params.size.width;
784
+ }
785
+ break;
786
+ }
787
+ }
788
+ return result;
789
+ };
790
+
791
+ const prop_align_new = function (raw) {
792
+ if (!raw) {
793
+ return "start";
794
+ }
795
+ if (raw === true) {
796
+ return "end";
797
+ }
798
+ return raw;
799
+ };
800
+
801
+ const prop_align_new_reversed = function (src_align) {
802
+ switch (src_align) {
803
+ case "start":
804
+ return "end";
805
+ case "end":
806
+ return "start";
807
+ }
808
+ return src_align;
809
+ };
810
+
811
+ const prop_clmap_def_content = {
812
+ __qyuddn: "__qyuddn",
813
+ content: "content",
814
+ _tracking: "_tracking",
815
+ focusguard: "focusguard",
816
+ };
817
+
818
+ const prop_clmap_def_listfix = {
819
+ __qyuddn: "__qyuddn",
820
+ listfix: "listfix",
821
+ _transition_nopos: "_transition_nopos",
822
+ _transition_nosize: "_transition_nosize",
823
+ _open: "_open",
824
+ _justify_start: "_justify_start",
825
+ _justify_end: "_justify_end",
826
+ _align_start: "_align_start",
827
+ _align_end: "_align_end",
828
+ _align_center: "_align_center",
829
+ _vertical: "_vertical",
830
+ _horizontal: "_horizontal",
831
+ };
832
+
833
+ const prop_clmap_new = function (stylemap, def) {
834
+ if (!stylemap) {
835
+ return def;
836
+ }
837
+ const result = {};
838
+ for (const clname of Object.keys(def)) {
839
+ const remaped = stylemap[clname];
840
+ if (remaped !== undefined) {
841
+ result[clname] = remaped;
842
+ continue;
843
+ }
844
+ {
845
+ result[clname] = clname;
846
+ }
847
+ }
848
+ return result;
849
+ };
850
+
851
+ const prop_direction_new = function (raw) {
852
+ if (!raw) {
853
+ return "ver";
854
+ }
855
+ if (raw === true) {
856
+ return "hor";
857
+ }
858
+ return raw;
859
+ };
860
+
861
+ const prop_justify_new = function (raw) {
862
+ if (!raw) {
863
+ return "end";
864
+ }
865
+ if (raw === true) {
866
+ return "start";
867
+ }
868
+ return raw;
869
+ };
870
+
871
+ const prop_justify_new_reversed = function (src_justify) {
872
+ switch (src_justify) {
873
+ case "start":
874
+ return "end";
875
+ case "end":
876
+ return "start";
877
+ }
878
+ return src_justify;
879
+ };
880
+
881
+ const render_view_default$4 = function (props) {
882
+ return jsx("div", { ...props });
883
+ };
884
+ const CmpListFix = r.memo(r.forwardRef((props, f_ref) => {
885
+ const nprop_gap = props.gap ?? 0;
886
+ const nprop_lazy = props.lazy ?? false;
887
+ const nprop_align = prop_align_new(props.align);
888
+ const nprop_justify = prop_justify_new(props.justify);
889
+ const nprop_direction = prop_direction_new(props.direction);
890
+ const nprop_transition_nopos = props.transition_nopos ?? false;
891
+ const nprop_transition_nosize = props.transition_nosize ?? false;
892
+ const nprop_render_view = props.render_view ?? render_view_default$4;
893
+ const nprop_clmap = r.useMemo(() => prop_clmap_new(props.clmap, prop_clmap_def_listfix), [props.clmap]);
894
+ const nprop_clmap_content = r.useMemo(() => prop_clmap_new(props.clmap_content, prop_clmap_def_content), [props.clmap_content]);
895
+ const l_ref = r.useRef(null);
896
+ const l_ref_content = r.useRef(null);
897
+ const ref_list = useRefO(l_ref);
898
+ const ref_content = useRefO(l_ref_content);
899
+ const open = useOpenInfer({});
900
+ const [visible, visible_set] = r.useState(false);
901
+ const listapi = useListPosApiFixed({ ref_list, ref_content, clmap_content: nprop_clmap_content });
902
+ const ctxstate_content = useCtxStateInitContent({
903
+ ref_content: l_ref_content,
904
+ });
905
+ useDDNListInfer({
906
+ visible,
907
+ });
908
+ useDDNShardInfer({
909
+ isolated: false,
910
+ ref: useRefO(l_ref),
911
+ });
912
+ useListPosRearrange({
913
+ open,
914
+ api: listapi.api,
915
+ active: visible || open,
916
+ rearrange_config: props.rearrange,
917
+ api_config: {
918
+ gap: nprop_gap,
919
+ align: nprop_align,
920
+ justify: nprop_justify,
921
+ direction: nprop_direction,
922
+ },
923
+ });
924
+ useFocusCaptureInfer({
925
+ open,
926
+ ref_target: useRefO(ctxstate_content.ref_content),
927
+ });
928
+ const ref = useRefMerge(l_ref, f_ref);
409
929
  const children = r.useMemo(() => {
410
- if (!nprop_lazy || visible || ctxstate.open) {
930
+ if (!nprop_lazy || visible || open) {
411
931
  if (typeof props.children === "function") {
412
932
  return props.children();
413
933
  }
414
934
  return props.children;
415
935
  }
416
936
  return null;
417
- }, [nprop_lazy, visible, ctxstate.open, props.children]);
418
- const element = jsx("div", { ref: mref, tabIndex: props.tabIndex, className: cl("__qyuddn", props.className, nprop_style.listfix, ctxstate.open && nprop_style.listfix_open, ((nprop_align === "end" && !revalign) || (nprop_align === "start" && revalign)) && nprop_style.listfix_align_end, ((nprop_align === "start" && !revalign) || (nprop_align === "end" && revalign)) && nprop_style.listfix_align_start, nprop_align === "center" && nprop_style.listfix_align_center, ((nprop_justify === "end") !== revjustify) && nprop_style.listfix_justify_end, ((nprop_justify === "start") !== revjustify) && nprop_style.listfix_justify_start, nprop_direction === "hor" && nprop_style.listfix_horizontal, nprop_direction === "ver" && nprop_style.listfix_vertical), style: {
419
- ["--gap"]: `${nprop_gap}px`,
420
- top: top !== null ? `${top}px` : null,
421
- left: left !== null ? `${left}px` : null,
422
- right: right !== null ? `${right}px` : null,
423
- bottom: bottom !== null ? `${bottom}px` : null,
424
- maxWidth: maxwidth === null ? undefined : `${maxwidth}px`,
425
- maxHeight: maxheight === null ? undefined : `${maxheight}px`,
426
- }, onTransitionStart: ev => {
427
- if (ev.nativeEvent.propertyName === "opacity" && ctxstate.open) {
428
- visible_set(true);
429
- }
430
- }, onTransitionEnd: ev => {
431
- if (ev.nativeEvent.propertyName === "opacity" && !ctxstate.open) {
432
- revalign_set(false);
433
- revjustify_set(false);
434
- maxwidth_set(null);
435
- maxheight_set(null);
436
- visible_set(false);
437
- top_set(null);
438
- bottom_set(null);
439
- left_set(null);
440
- right_set(null);
441
- }
442
- }, children: children });
443
- if (nprop_portal) {
444
- return rdom.createPortal(element, nprop_portal);
445
- }
446
- return element;
937
+ }, [nprop_lazy, visible, open, props.children]);
938
+ const view_align = listapi.reverse.align ? prop_align_new_reversed(nprop_align) : nprop_align;
939
+ const view_justify = listapi.reverse.justify ? prop_justify_new_reversed(nprop_justify) : nprop_justify;
940
+ return jsx(CmpCtxState_Content.Provider, { value: ctxstate_content, children: nprop_render_view({
941
+ ref,
942
+ children,
943
+ className: cl(nprop_clmap.__qyuddn, nprop_clmap.listfix, open && nprop_clmap._open, nprop_transition_nopos && nprop_clmap._transition_nopos, nprop_transition_nosize && nprop_clmap._transition_nosize, view_align === "end" && nprop_clmap._align_end, view_align === "start" && nprop_clmap._align_start, view_align === "center" && nprop_clmap._align_center, view_justify === "end" && nprop_clmap._justify_end, view_justify === "start" && nprop_clmap._justify_start, nprop_direction === "hor" && nprop_clmap._horizontal, nprop_direction === "ver" && nprop_clmap._vertical, props.className),
944
+ style: {
945
+ ["--gap"]: `${nprop_gap}px`,
946
+ ...cssprops_new_position(listapi.position),
947
+ ...cssprops_new_size({
948
+ size: listapi.size,
949
+ open: open,
950
+ direction: nprop_direction,
951
+ }),
952
+ },
953
+ onTransitionStart: ev => {
954
+ props.event_transition_change?.(ev.nativeEvent.propertyName, true);
955
+ if (ev.nativeEvent.propertyName === "opacity" && open) {
956
+ visible_set(true);
957
+ props.event_visible_change?.(true);
958
+ }
959
+ },
960
+ onTransitionEnd: ev => {
961
+ props.event_transition_change?.(ev.nativeEvent.propertyName, false);
962
+ if (ev.nativeEvent.propertyName === "opacity" && !open) {
963
+ listapi.api.clear();
964
+ visible_set(false);
965
+ props.event_visible_change?.(false);
966
+ }
967
+ },
968
+ }) });
447
969
  }));
448
970
 
449
- const stylemap = {
450
- listabs: "listabs",
451
- listabs_open: "listabs_open",
452
- listabs_justify_start: "listabs_justify_start",
453
- listabs_justify_end: "listabs_justify_end",
454
- listabs_align_start: "listabs_align_start",
455
- listabs_align_end: "listabs_align_end",
456
- listabs_align_center: "listabs_align_center",
457
- listabs_vertical: "listabs_vertical",
458
- listabs_horizontal: "listabs_horizontal",
459
- };
460
971
  const normalize_justify = function (params) {
461
972
  let axis_main;
462
973
  switch (params.direction) {
@@ -483,21 +994,13 @@ const normalize_justify = function (params) {
483
994
  break;
484
995
  }
485
996
  }
486
- if (freespace_direct >= axis_main.list_size) {
487
- params.reverse_justify_set(false);
488
- axis_main.space_set(null);
489
- }
490
- else if (freespace_reverse >= axis_main.list_size) {
491
- params.reverse_justify_set(true);
492
- axis_main.space_set(null);
493
- }
494
- else if (freespace_direct >= freespace_reverse) {
495
- params.reverse_justify_set(false);
496
- axis_main.space_set(freespace_direct);
997
+ if (freespace_direct >= axis_main.list_size || freespace_direct >= freespace_reverse) {
998
+ params.reverse_set(false);
999
+ axis_main.size_set(Math.min(freespace_direct, axis_main.list_size));
497
1000
  }
498
1001
  else {
499
- params.reverse_justify_set(true);
500
- axis_main.space_set(freespace_reverse);
1002
+ params.reverse_set(true);
1003
+ axis_main.size_set(Math.min(freespace_reverse, axis_main.list_size));
501
1004
  }
502
1005
  };
503
1006
  const normalize_align = function (params) {
@@ -516,8 +1019,10 @@ const normalize_align = function (params) {
516
1019
  let freespace_reverse;
517
1020
  switch (params.align) {
518
1021
  case "center": {
519
- params.reverse_align_set(false);
520
- axis_main.space_set(null);
1022
+ const point = axis_main.container_pos + (axis_main.container_size / 2);
1023
+ const freespace = Math.max(Math.min(point, axis_main.screen_size - point), 0) * 2;
1024
+ params.reverse_set(false);
1025
+ axis_main.size_set(Math.min(freespace, axis_main.list_size));
521
1026
  return;
522
1027
  }
523
1028
  case "start": {
@@ -531,117 +1036,480 @@ const normalize_align = function (params) {
531
1036
  break;
532
1037
  }
533
1038
  }
534
- if (freespace_direct >= axis_main.list_size) {
535
- params.reverse_align_set(false);
536
- axis_main.space_set(null);
537
- }
538
- else if (freespace_reverse >= axis_main.list_size) {
539
- params.reverse_align_set(true);
540
- axis_main.space_set(null);
541
- }
542
- else if (freespace_direct >= freespace_reverse) {
543
- params.reverse_align_set(false);
544
- axis_main.space_set(freespace_direct);
1039
+ if (freespace_direct >= axis_main.list_size || freespace_direct >= freespace_reverse) {
1040
+ params.reverse_set(false);
1041
+ axis_main.size_set(Math.min(freespace_direct, axis_main.list_size));
545
1042
  }
546
1043
  else {
547
- params.reverse_align_set(true);
548
- axis_main.space_set(freespace_reverse);
1044
+ params.reverse_set(true);
1045
+ axis_main.size_set(Math.min(freespace_reverse, axis_main.list_size));
549
1046
  }
550
1047
  };
551
- const CmpListAbs = r.memo(r.forwardRef((props, ref) => {
1048
+ const useListPosApiAbsolute = function (params) {
1049
+ const ctxstate_refs = useCtxStateRefs();
1050
+ const [align_reverse, align_reverse_set] = r.useState(false);
1051
+ const [justify_reverse, justify_reverse_set] = r.useState(false);
1052
+ const [width, width_set] = r.useState(null);
1053
+ const [height, height_set] = r.useState(null);
1054
+ return {
1055
+ size: r.useMemo(() => ({
1056
+ width: width,
1057
+ height: height,
1058
+ }), [width, height]),
1059
+ reverse: r.useMemo(() => ({
1060
+ align: align_reverse,
1061
+ justify: justify_reverse,
1062
+ }), [align_reverse, justify_reverse]),
1063
+ api: r.useMemo(() => ({
1064
+ clear: () => {
1065
+ align_reverse_set(false);
1066
+ justify_reverse_set(false);
1067
+ width_set(null);
1068
+ height_set(null);
1069
+ },
1070
+ rearrange: config => {
1071
+ const list = params.ref_list();
1072
+ const content = params.ref_content();
1073
+ const container = [...ctxstate_refs.rootref].map(ref => ref()).find(el => el !== null);
1074
+ if (list && container && content) {
1075
+ if (params.clmap_content._tracking) {
1076
+ content.classList.add(params.clmap_content._tracking);
1077
+ }
1078
+ const container_rect = container.getBoundingClientRect();
1079
+ const axis_main = {
1080
+ size_set: height_set,
1081
+ list_size: content.offsetHeight,
1082
+ screen_size: document.documentElement.clientHeight,
1083
+ container_pos: container_rect.y,
1084
+ container_size: container_rect.height,
1085
+ };
1086
+ const axis_cross = {
1087
+ size_set: width_set,
1088
+ list_size: content.offsetWidth,
1089
+ screen_size: document.documentElement.clientWidth,
1090
+ container_pos: container_rect.x,
1091
+ container_size: container_rect.width,
1092
+ };
1093
+ normalize_justify({
1094
+ axis_main,
1095
+ axis_cross,
1096
+ gap: config.gap,
1097
+ justify: config.justify,
1098
+ direction: config.direction,
1099
+ reverse_set: justify_reverse_set,
1100
+ });
1101
+ normalize_align({
1102
+ axis_main,
1103
+ axis_cross,
1104
+ align: config.align,
1105
+ direction: config.direction,
1106
+ reverse_set: align_reverse_set,
1107
+ });
1108
+ if (params.clmap_content._tracking) {
1109
+ content.classList.remove(params.clmap_content._tracking);
1110
+ }
1111
+ }
1112
+ },
1113
+ }), [ctxstate_refs.rootref, params.ref_list, params.ref_content, params.clmap_content])
1114
+ };
1115
+ };
1116
+
1117
+ const prop_clmap_def_listabs = {
1118
+ __qyuddn: "__qyuddn",
1119
+ listabs: "listabs",
1120
+ _transition_nosize: "_transition_nosize",
1121
+ _open: "_open",
1122
+ _justify_start: "_justify_start",
1123
+ _justify_end: "_justify_end",
1124
+ _align_start: "_align_start",
1125
+ _align_end: "_align_end",
1126
+ _align_center: "_align_center",
1127
+ _vertical: "_vertical",
1128
+ _horizontal: "_horizontal",
1129
+ };
1130
+
1131
+ const render_view_default$3 = function (props) {
1132
+ return jsx("div", { ...props });
1133
+ };
1134
+ const CmpListAbs = r.memo(r.forwardRef((props, f_ref) => {
552
1135
  const nprop_gap = props.gap ?? 0;
553
- const nprop_lazy = props.lazy ?? false;
554
- const nprop_align = nprop_align_new(props.align);
555
- const nprop_justify = nprop_justify_new(props.justify);
556
- const nprop_direction = nprop_direction_new(props.direction);
557
- const nprop_style = r.useMemo(() => (props.stylemodule ? stylemap_new_remap(stylemap, props.stylemodule) : stylemap), [props.stylemodule]);
558
- const ctxstate = r.useContext(CmpCtxState_Open);
559
- if (!ctxstate) {
560
- throw new Error(`Using DDN dependend component outside of DDN Context`);
561
- }
1136
+ const nprop_lazy = props.lazy ?? true;
1137
+ const nprop_align = prop_align_new(props.align);
1138
+ const nprop_justify = prop_justify_new(props.justify);
1139
+ const nprop_direction = prop_direction_new(props.direction);
1140
+ const nprop_render_view = props.render_view ?? render_view_default$3;
1141
+ const nprop_clmap = r.useMemo(() => prop_clmap_new(props.clmap, prop_clmap_def_listabs), [props.clmap]);
1142
+ const nprop_clmap_content = r.useMemo(() => prop_clmap_new(props.clmap_content, prop_clmap_def_content), [props.clmap_content]);
1143
+ const nprop_transition_nosize = props.transition_nosize ?? false;
562
1144
  const l_ref = r.useRef(null);
1145
+ const l_ref_content = r.useRef(null);
1146
+ const ref_list = useRefO(l_ref);
1147
+ const ref_content = useRefO(l_ref_content);
1148
+ const open = useOpenInfer({});
563
1149
  const [visible, visible_set] = r.useState(false);
564
- const [revalign, revalign_set] = r.useState(false);
565
- const [revjustify, revjustify_set] = r.useState(false);
566
- const [maxheight, maxheight_set] = r.useState(null);
567
- const [maxwidth, maxwidth_set] = r.useState(null);
568
- r.useLayoutEffect(() => {
569
- const list = l_ref.current;
570
- const container = ctxstate.ref.current;
571
- if (list && container && ctxstate.open) {
572
- const container_rect = container.getBoundingClientRect();
573
- const axis_main = {
574
- list_size: list.offsetHeight,
575
- space_set: maxheight_set,
576
- screen_size: document.documentElement.clientHeight,
577
- container_pos: container_rect.y,
578
- container_size: container_rect.height,
579
- };
580
- const axis_cross = {
581
- list_size: list.offsetWidth,
582
- space_set: maxwidth_set,
583
- screen_size: document.documentElement.clientWidth,
584
- container_pos: container_rect.x,
585
- container_size: container_rect.width,
586
- };
587
- normalize_justify({
588
- axis_main,
589
- axis_cross,
590
- gap: nprop_gap,
591
- justify: nprop_justify,
592
- direction: nprop_direction,
593
- reverse_align_set: revalign_set,
594
- reverse_justify_set: revjustify_set,
595
- });
596
- normalize_align({
597
- axis_main,
598
- axis_cross,
599
- align: nprop_align,
600
- direction: nprop_direction,
601
- reverse_align_set: revalign_set,
602
- reverse_justify_set: revjustify_set,
603
- });
1150
+ const listapi = useListPosApiAbsolute({ ref_list, ref_content, clmap_content: nprop_clmap_content });
1151
+ const ctxstate_content = useCtxStateInitContent({
1152
+ ref_content: l_ref_content,
1153
+ });
1154
+ useDDNListInfer({
1155
+ visible,
1156
+ });
1157
+ useDDNShardInfer({
1158
+ isolated: false,
1159
+ ref: useRefO(l_ref),
1160
+ });
1161
+ useListPosRearrange({
1162
+ open,
1163
+ api: listapi.api,
1164
+ active: visible || open,
1165
+ rearrange_config: props.rearrange,
1166
+ api_config: {
1167
+ gap: nprop_gap,
1168
+ align: nprop_align,
1169
+ justify: nprop_justify,
1170
+ direction: nprop_direction,
1171
+ },
1172
+ });
1173
+ useFocusCaptureInfer({
1174
+ open,
1175
+ ref_target: useRefO(ctxstate_content.ref_content),
1176
+ });
1177
+ const ref = useRefMerge(l_ref, f_ref);
1178
+ const children = r.useMemo(() => {
1179
+ if (!nprop_lazy || visible || open) {
1180
+ if (typeof props.children === "function") {
1181
+ return props.children();
1182
+ }
1183
+ return props.children;
604
1184
  }
605
- }, [ctxstate.open, ctxstate.ref, nprop_gap, nprop_align, nprop_justify, nprop_direction]);
606
- const mref = r.useMemo(() => {
607
- return (element) => {
608
- l_ref.current = element;
609
- if (ref) {
610
- if (typeof ref === "object") {
611
- ref.current = element;
1185
+ return null;
1186
+ }, [nprop_lazy, visible, open, props.children]);
1187
+ const view_align = listapi.reverse.align ? prop_align_new_reversed(nprop_align) : nprop_align;
1188
+ const view_justify = listapi.reverse.justify ? prop_justify_new_reversed(nprop_justify) : nprop_justify;
1189
+ return jsx(CmpCtxState_Content, { value: ctxstate_content, children: nprop_render_view({
1190
+ ref,
1191
+ children,
1192
+ className: cl(nprop_clmap.__qyuddn, nprop_clmap.listabs, open && nprop_clmap._open, nprop_transition_nosize && nprop_clmap._transition_nosize, view_align === "end" && nprop_clmap._align_end, view_align === "start" && nprop_clmap._align_start, view_align === "center" && nprop_clmap._align_center, view_justify === "end" && nprop_clmap._justify_end, view_justify === "start" && nprop_clmap._justify_start, nprop_direction === "hor" && nprop_clmap._horizontal, nprop_direction === "ver" && nprop_clmap._vertical, props.className),
1193
+ style: {
1194
+ ["--gap"]: `${nprop_gap}px`,
1195
+ ...cssprops_new_size({
1196
+ size: listapi.size,
1197
+ open: open,
1198
+ direction: nprop_direction,
1199
+ }),
1200
+ },
1201
+ onTransitionStart: ev => {
1202
+ props.event_transition_change?.(ev.nativeEvent.propertyName, true);
1203
+ if (ev.nativeEvent.propertyName === "opacity" && open) {
1204
+ visible_set(true);
1205
+ props.event_visible_change?.(true);
612
1206
  }
613
- else {
614
- ref(element);
1207
+ },
1208
+ onTransitionEnd: ev => {
1209
+ props.event_transition_change?.(ev.nativeEvent.propertyName, false);
1210
+ if (ev.nativeEvent.propertyName === "opacity" && !open) {
1211
+ listapi.api.clear();
1212
+ visible_set(false);
1213
+ props.event_visible_change?.(false);
615
1214
  }
616
- }
617
- };
618
- }, [ref]);
1215
+ },
1216
+ }) });
1217
+ }));
1218
+
1219
+ const prop_portal_new = function (portal) {
1220
+ if (typeof portal === "string") {
1221
+ return document.getElementById(portal) ?? null;
1222
+ }
1223
+ if (portal) {
1224
+ return portal;
1225
+ }
1226
+ return null;
1227
+ };
1228
+
1229
+ const render_view_default$2 = function (props) {
1230
+ return jsx("div", { ...props });
1231
+ };
1232
+ const CmpListPortal = r.memo(r.forwardRef((props, f_ref) => {
1233
+ const nprop_gap = props.gap ?? 0;
1234
+ const nprop_lazy = props.lazy ?? true;
1235
+ const nprop_align = prop_align_new(props.align);
1236
+ const nprop_portal = prop_portal_new(props.portal);
1237
+ const nprop_justify = prop_justify_new(props.justify);
1238
+ const nprop_direction = prop_direction_new(props.direction);
1239
+ const nprop_transition_nopos = props.transition_nopos ?? false;
1240
+ const nprop_transition_nosize = props.transition_nosize ?? false;
1241
+ const nprop_render_view = props.render_view ?? render_view_default$2;
1242
+ const nprop_clmap = r.useMemo(() => prop_clmap_new(props.clmap, prop_clmap_def_listfix), [props.clmap]);
1243
+ const nprop_clmap_content = r.useMemo(() => prop_clmap_new(props.clmap_content, prop_clmap_def_content), [props.clmap_content]);
1244
+ const l_ref = r.useRef(null);
1245
+ const l_ref_content = r.useRef(null);
1246
+ const ref_list = useRefO(l_ref);
1247
+ const ref_content = useRefO(l_ref_content);
1248
+ const open = useOpenInfer({});
1249
+ const [visible, visible_set] = r.useState(false);
1250
+ const listapi = useListPosApiFixed({ ref_list, ref_content, clmap_content: nprop_clmap_content });
1251
+ const ctxstate_content = useCtxStateInitContent({
1252
+ ref_content: l_ref_content,
1253
+ });
1254
+ useDDNListInfer({
1255
+ visible: visible || open,
1256
+ });
1257
+ useDDNShardInfer({
1258
+ isolated: true,
1259
+ ref: useRefO(l_ref),
1260
+ });
1261
+ useListPosRearrange({
1262
+ open,
1263
+ api: listapi.api,
1264
+ active: visible || open,
1265
+ rearrange_config: props.rearrange,
1266
+ api_config: {
1267
+ gap: nprop_gap,
1268
+ align: nprop_align,
1269
+ justify: nprop_justify,
1270
+ direction: nprop_direction,
1271
+ },
1272
+ });
1273
+ useFocusCaptureInfer({
1274
+ open,
1275
+ ref_target: useRefO(ctxstate_content.ref_content),
1276
+ });
1277
+ const ref = useRefMerge(l_ref, f_ref);
619
1278
  const children = r.useMemo(() => {
620
- if (!nprop_lazy || visible || ctxstate.open) {
1279
+ if (!nprop_lazy || visible || open) {
621
1280
  if (typeof props.children === "function") {
622
1281
  return props.children();
623
1282
  }
624
1283
  return props.children;
625
1284
  }
626
1285
  return null;
627
- }, [nprop_lazy, visible, ctxstate.open, props.children]);
628
- return jsx("div", { ref: mref, tabIndex: props.tabIndex, className: cl("__qyuddn", props.className, nprop_style.listabs, ctxstate.open && nprop_style.listabs_open, ((nprop_align === "end" && !revalign) || (nprop_align === "start" && revalign)) && nprop_style.listabs_align_end, ((nprop_align === "start" && !revalign) || (nprop_align === "end" && revalign)) && nprop_style.listabs_align_start, nprop_align === "center" && nprop_style.listabs_align_center, ((nprop_justify === "end") !== revjustify) && nprop_style.listabs_justify_end, ((nprop_justify === "start") !== revjustify) && nprop_style.listabs_justify_start, nprop_direction === "hor" && nprop_style.listabs_horizontal, nprop_direction === "ver" && nprop_style.listabs_vertical), style: {
629
- ["--gap"]: `${nprop_gap}px`,
630
- maxWidth: maxwidth === null ? undefined : `${maxwidth}px`,
631
- maxHeight: maxheight === null ? undefined : `${maxheight}px`,
632
- }, onTransitionStart: ev => {
633
- if (ev.nativeEvent.propertyName === "opacity" && ctxstate.open) {
634
- visible_set(true);
1286
+ }, [nprop_lazy, visible, open, props.children]);
1287
+ const view_align = listapi.reverse.align ? prop_align_new_reversed(nprop_align) : nprop_align;
1288
+ const view_justify = listapi.reverse.justify ? prop_justify_new_reversed(nprop_justify) : nprop_justify;
1289
+ if (nprop_portal) {
1290
+ return rdom.createPortal(jsx(CmpCtxState_Content.Provider, { value: ctxstate_content, children: nprop_render_view({
1291
+ ref,
1292
+ children,
1293
+ className: cl(nprop_clmap.__qyuddn, nprop_clmap.listfix, open && nprop_clmap._open, nprop_transition_nopos && nprop_clmap._transition_nopos, nprop_transition_nosize && nprop_clmap._transition_nosize, view_align === "end" && nprop_clmap._align_end, view_align === "start" && nprop_clmap._align_start, view_align === "center" && nprop_clmap._align_center, view_justify === "end" && nprop_clmap._justify_end, view_justify === "start" && nprop_clmap._justify_start, nprop_direction === "hor" && nprop_clmap._horizontal, nprop_direction === "ver" && nprop_clmap._vertical, props.className),
1294
+ style: {
1295
+ ["--gap"]: `${nprop_gap}px`,
1296
+ ...cssprops_new_position(listapi.position),
1297
+ ...cssprops_new_size({
1298
+ size: listapi.size,
1299
+ open: open,
1300
+ direction: nprop_direction,
1301
+ }),
1302
+ },
1303
+ onTransitionStart: ev => {
1304
+ props.event_transition_change?.(ev.nativeEvent.propertyName, true);
1305
+ if (ev.nativeEvent.propertyName === "opacity" && open) {
1306
+ visible_set(true);
1307
+ props.event_visible_change?.(true);
1308
+ }
1309
+ },
1310
+ onTransitionEnd: ev => {
1311
+ props.event_transition_change?.(ev.nativeEvent.propertyName, false);
1312
+ if (ev.nativeEvent.propertyName === "opacity" && !open) {
1313
+ listapi.api.clear();
1314
+ visible_set(false);
1315
+ props.event_visible_change?.(false);
1316
+ }
1317
+ },
1318
+ }) }), nprop_portal);
1319
+ }
1320
+ return null;
1321
+ }));
1322
+
1323
+ const render_view_default$1 = function (props) {
1324
+ return jsx("div", { ...props });
1325
+ };
1326
+ const CmpContent = r.memo(r.forwardRef((props, f_ref) => {
1327
+ const nprop_container = props.render_view ?? render_view_default$1;
1328
+ const nprop_clmap = r.useMemo(() => prop_clmap_new(props.clmap, prop_clmap_def_content), [props.clmap]);
1329
+ const ctxstate_content = useCtxStateContent();
1330
+ const ref = useRefMerge(f_ref, ctxstate_content.ref_content);
1331
+ return jsxs(Fragment, { children: [props.focus_noguards
1332
+ ? null
1333
+ : jsx("input", { "data-focusguard": true, tabIndex: 0, className: cl(nprop_clmap.__qyuddn, nprop_clmap.focusguard) }), nprop_container({
1334
+ ref: ref,
1335
+ children: props.children,
1336
+ tabIndex: 0,
1337
+ className: cl(nprop_clmap.__qyuddn, nprop_clmap.content, props.className),
1338
+ }), props.focus_noguards
1339
+ ? null
1340
+ : jsx("input", { "data-focusguard": true, tabIndex: 0, className: cl(nprop_clmap.__qyuddn, nprop_clmap.focusguard) })] });
1341
+ }));
1342
+
1343
+ const refs_unpack = function* (src) {
1344
+ for (const ref of src) {
1345
+ const element = ref();
1346
+ if (element) {
1347
+ yield element;
1348
+ }
1349
+ }
1350
+ };
1351
+ const element_outside = function (element, shards) {
1352
+ for (const ref of shards) {
1353
+ if (ref === element || ref.contains(element)) {
1354
+ return false;
1355
+ }
1356
+ }
1357
+ return true;
1358
+ };
1359
+ const useCloseEvtRoot = function (params) {
1360
+ const { ctxstate_open, ctxstate_refs, ctxstate_config } = params;
1361
+ const nconfig_blur = ctxstate_config.closeevt.blur ?? true;
1362
+ const nconfig_click = ctxstate_config.closeevt.click ?? true;
1363
+ const nconfig_resize = ctxstate_config.closeevt.resize ?? true;
1364
+ const nconfig_escape = ctxstate_config.closeevt.escape ?? true;
1365
+ const open = useOpen({ ctxstate_open, ctxstate_refs, });
1366
+ r.useEffect(() => {
1367
+ if (params.active && open) {
1368
+ const controller = new AbortController();
1369
+ if (nconfig_blur) {
1370
+ document.addEventListener("focusin", ev => {
1371
+ if (ev.target instanceof Element) {
1372
+ if (ev.target.hasAttribute("data-focusguard")) {
1373
+ if (element_outside(ev.target, refs_unpack(ctxstate_refs.register.it_down))) {
1374
+ ctxstate_open.open_set(false);
1375
+ }
1376
+ }
1377
+ else if (element_outside(ev.target, refs_unpack(ctxstate_refs.register.it_context))) {
1378
+ ctxstate_open.open_set(false);
1379
+ }
1380
+ }
1381
+ }, { signal: controller.signal });
1382
+ }
1383
+ if (nconfig_click) {
1384
+ document.addEventListener("click", ev => {
1385
+ const shards = refs_unpack(ctxstate_refs.register.it_context);
1386
+ if (ev.target instanceof Element) {
1387
+ if (element_outside(ev.target, shards)) {
1388
+ ctxstate_open.open_set(false);
1389
+ }
1390
+ }
1391
+ }, { signal: controller.signal });
1392
+ }
1393
+ if (nconfig_escape) {
1394
+ document.addEventListener("keydown", ev => {
1395
+ if (ev.key.toLowerCase() === "escape") {
1396
+ ctxstate_open.open_set(false);
1397
+ }
1398
+ }, { signal: controller.signal });
635
1399
  }
636
- }, onTransitionEnd: ev => {
637
- if (ev.nativeEvent.propertyName === "opacity" && !ctxstate.open) {
638
- revalign_set(false);
639
- revjustify_set(false);
640
- maxwidth_set(null);
641
- maxheight_set(null);
642
- visible_set(false);
1400
+ if (nconfig_resize) {
1401
+ window.addEventListener("resize", () => {
1402
+ ctxstate_open.open_set(false);
1403
+ }, { signal: controller.signal });
643
1404
  }
644
- }, children: children });
1405
+ return () => {
1406
+ controller.abort();
1407
+ };
1408
+ }
1409
+ }, [
1410
+ open,
1411
+ ctxstate_refs.register,
1412
+ ctxstate_open.open_set,
1413
+ params.active,
1414
+ nconfig_click,
1415
+ nconfig_resize,
1416
+ nconfig_escape,
1417
+ nconfig_blur,
1418
+ ]);
1419
+ };
1420
+
1421
+ const prop_clmap_def_container = {
1422
+ __qyuddn: "__qyuddn",
1423
+ container: "container",
1424
+ };
1425
+
1426
+ const render_view_default = function (props) {
1427
+ return jsx("div", { ...props });
1428
+ };
1429
+ const CmpContainer = r.memo(r.forwardRef((props, f_ref) => {
1430
+ const nprop_clmap = r.useMemo(() => prop_clmap_new(props.clmap, prop_clmap_def_container), [props.clmap]);
1431
+ const nprop_render_view = props.render_view ?? render_view_default;
1432
+ const l_ref = r.useRef(null);
1433
+ const ctxstate_open = useCtxStateInitOpen({
1434
+ open: props.open,
1435
+ open_set: props.open_set,
1436
+ });
1437
+ const ctxstate_refs = useCtxStateInitRefs({
1438
+ container_real: true
1439
+ });
1440
+ const ctxstate_config = useCtxStateInitConfig({
1441
+ focus: props.focus,
1442
+ closeevt: props.closeevt,
1443
+ });
1444
+ useDDNRoot({
1445
+ active: true,
1446
+ ref: useRefO(l_ref),
1447
+ ctxstate_refs,
1448
+ });
1449
+ useDDNShard({
1450
+ isolated: true,
1451
+ ref: useRefO(l_ref),
1452
+ ctxstate_refs,
1453
+ ctxstate_open,
1454
+ ctxstate_config,
1455
+ });
1456
+ useCloseEvtRoot({
1457
+ active: true,
1458
+ ctxstate_open,
1459
+ ctxstate_refs,
1460
+ ctxstate_config,
1461
+ });
1462
+ const ref = useRefMerge(l_ref, f_ref);
1463
+ return jsx(CmpCtxState_Config.Provider, { value: ctxstate_config, children: jsx(CmpCtxState_Open.Provider, { value: ctxstate_open, children: jsx(CmpCtxState_Refs.Provider, { value: ctxstate_refs, children: nprop_render_view({
1464
+ ref,
1465
+ children: props.children,
1466
+ className: cl(nprop_clmap.__qyuddn, nprop_clmap.container, props.className),
1467
+ }) }) }) });
645
1468
  }));
646
1469
 
647
- export { CmpButton, CmpContainer, CmpCtxState_Open, CmpListAbs, CmpListFix, useDropdownCloseEvents };
1470
+ const CmpContainerVirtual = r.memo((props) => {
1471
+ const ctxstate_open = useCtxStateInitOpen({
1472
+ open: props.open,
1473
+ open_set: props.open_set,
1474
+ });
1475
+ const ctxstate_refs = useCtxStateInitRefs({
1476
+ container_real: false,
1477
+ });
1478
+ const ctxstate_config = useCtxStateInitConfig({
1479
+ focus: props.focus,
1480
+ closeevt: props.closeevt,
1481
+ });
1482
+ useCloseEvtRoot({
1483
+ active: true,
1484
+ ctxstate_refs,
1485
+ ctxstate_open,
1486
+ ctxstate_config,
1487
+ });
1488
+ return jsx(CmpCtxState_Config.Provider, { value: ctxstate_config, children: jsx(CmpCtxState_Open.Provider, { value: ctxstate_open, children: jsx(CmpCtxState_Refs.Provider, { value: ctxstate_refs, children: props.children }) }) });
1489
+ });
1490
+
1491
+ const useCloseEvtRootInfer = function (params) {
1492
+ const ctxstate_refs = useCtxStateRefs();
1493
+ const ctxstate_open = useCtxStateOpen();
1494
+ const ctxstate_config = useCtxStateConfig();
1495
+ useCloseEvtRoot({
1496
+ ...params,
1497
+ ctxstate_refs,
1498
+ ctxstate_open,
1499
+ ctxstate_config,
1500
+ });
1501
+ };
1502
+
1503
+ const useCloseEvtShardInfer = function (params) {
1504
+ const ctxstate_refs = useCtxStateRefs();
1505
+ const ctxstate_open = useCtxStateOpen();
1506
+ const ctxstate_config = useCtxStateConfig();
1507
+ useCloseEvtShard({
1508
+ ...params,
1509
+ ctxstate_refs,
1510
+ ctxstate_open,
1511
+ ctxstate_config,
1512
+ });
1513
+ };
1514
+
1515
+ export { CmpButton, CmpButtonVirtual, CmpContainer, CmpContainerVirtual, CmpContent, CmpCtxState_Config, CmpCtxState_Content, CmpCtxState_Open, CmpCtxState_Refs, CmpListAbs, CmpListFix, CmpListPortal, cssprops_new_position, cssprops_new_size, prop_align_new, prop_align_new_reversed, prop_clmap_def_container, prop_clmap_def_content, prop_clmap_def_listabs, prop_clmap_def_listfix, prop_clmap_new, prop_direction_new, prop_justify_new, prop_justify_new_reversed, prop_portal_new, useCloseEvtRoot, useCloseEvtRootInfer, useCloseEvtShard, useCloseEvtShardInfer, useCtxStateConfig, useCtxStateContent, useCtxStateInitConfig, useCtxStateInitContent, useCtxStateInitOpen, useCtxStateInitRefs, useCtxStateOpen, useCtxStateRefs, useDDNList, useDDNListInfer, useDDNRoot, useDDNRootInfer, useDDNShard, useDDNShardInfer, useFocusCapture, useFocusCaptureInfer, useListPosApiAbsolute, useListPosApiFixed, useListPosRearrange, useOpen, useOpenInfer };