@almadar/ui 2.1.3 → 2.1.4

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.
@@ -1,30 +1,7 @@
1
1
  import { useUISlotManager } from './chunk-7NEWMNNU.js';
2
- import { createContext, useMemo, useContext, useState, useEffect, useCallback } from 'react';
2
+ import { createContext, useMemo, useState, useEffect, useCallback, useContext } from 'react';
3
3
  import { jsx } from 'react/jsx-runtime';
4
4
 
5
- var UISlotContext = createContext(null);
6
- function UISlotProvider({ children }) {
7
- const slotManager = useUISlotManager();
8
- const contextValue = useMemo(() => slotManager, [slotManager]);
9
- return /* @__PURE__ */ jsx(UISlotContext.Provider, { value: contextValue, children });
10
- }
11
- function useUISlots() {
12
- const context = useContext(UISlotContext);
13
- if (!context) {
14
- throw new Error(
15
- "useUISlots must be used within a UISlotProvider. Make sure your component tree is wrapped with <UISlotProvider>."
16
- );
17
- }
18
- return context;
19
- }
20
- function useSlotContent(slot) {
21
- const { getContent } = useUISlots();
22
- return getContent(slot);
23
- }
24
- function useSlotHasContent(slot) {
25
- const { hasContent } = useUISlots();
26
- return hasContent(slot);
27
- }
28
5
  var BUILT_IN_THEMES = [
29
6
  {
30
7
  name: "wireframe",
@@ -275,5 +252,28 @@ function useTheme() {
275
252
  return context;
276
253
  }
277
254
  var ThemeContext_default = ThemeContext;
255
+ var UISlotContext = createContext(null);
256
+ function UISlotProvider({ children }) {
257
+ const slotManager = useUISlotManager();
258
+ const contextValue = useMemo(() => slotManager, [slotManager]);
259
+ return /* @__PURE__ */ jsx(UISlotContext.Provider, { value: contextValue, children });
260
+ }
261
+ function useUISlots() {
262
+ const context = useContext(UISlotContext);
263
+ if (!context) {
264
+ throw new Error(
265
+ "useUISlots must be used within a UISlotProvider. Make sure your component tree is wrapped with <UISlotProvider>."
266
+ );
267
+ }
268
+ return context;
269
+ }
270
+ function useSlotContent(slot) {
271
+ const { getContent } = useUISlots();
272
+ return getContent(slot);
273
+ }
274
+ function useSlotHasContent(slot) {
275
+ const { hasContent } = useUISlots();
276
+ return hasContent(slot);
277
+ }
278
278
 
279
279
  export { BUILT_IN_THEMES, ThemeContext_default, ThemeProvider, UISlotContext, UISlotProvider, useSlotContent, useSlotHasContent, useTheme, useUISlots };
@@ -1,5 +1,5 @@
1
1
  import { apiClient } from './chunk-XSEDIUM6.js';
2
- import { SelectionContext, entityDataKeys, useEntityList } from './chunk-PE2H3NAW.js';
2
+ import { SelectionContext, entityDataKeys, useEntityList } from './chunk-JLEMVREZ.js';
3
3
  import { useEventBus } from './chunk-YXZM3WCF.js';
4
4
  import { subscribe, getSnapshot, clearEntities, removeEntity, updateSingleton, updateEntity, spawnEntity, getSingleton, getAllEntities, getByType, getEntity } from './chunk-N7MVUW4R.js';
5
5
  import { useCallback, useState, useEffect, useMemo, useContext, useSyncExternalStore } from 'react';
@@ -1,5 +1,5 @@
1
1
  import { useEventBus } from './chunk-YXZM3WCF.js';
2
- import React, { createContext, useContext, useState, useMemo, useCallback, useEffect } from 'react';
2
+ import React2, { createContext, useContext, useState, useMemo, useCallback, useEffect } from 'react';
3
3
  import { jsx } from 'react/jsx-runtime';
4
4
 
5
5
  var I18nContext = createContext({
@@ -90,12 +90,99 @@ function parseQueryBinding(binding) {
90
90
  field: parts.length > 1 ? parts.slice(1).join(".") : void 0
91
91
  };
92
92
  }
93
+ var SelectionContext = createContext(null);
94
+ var defaultCompareEntities = (a, b) => {
95
+ if (a === b) return true;
96
+ if (!a || !b) return false;
97
+ if (typeof a === "object" && typeof b === "object") {
98
+ const aId = a.id;
99
+ const bId = b.id;
100
+ return aId !== void 0 && aId === bId;
101
+ }
102
+ return false;
103
+ };
104
+ function SelectionProvider({
105
+ children,
106
+ debug = false,
107
+ compareEntities = defaultCompareEntities
108
+ }) {
109
+ const eventBus = useEventBus();
110
+ const [selected, setSelectedState] = useState(null);
111
+ const setSelected = useCallback(
112
+ (entity) => {
113
+ setSelectedState(entity);
114
+ if (debug) {
115
+ console.log("[SelectionProvider] Selection set:", entity);
116
+ }
117
+ },
118
+ [debug]
119
+ );
120
+ const clearSelection = useCallback(() => {
121
+ setSelectedState(null);
122
+ if (debug) {
123
+ console.log("[SelectionProvider] Selection cleared");
124
+ }
125
+ }, [debug]);
126
+ const isSelected = useCallback(
127
+ (entity) => {
128
+ return compareEntities(selected, entity);
129
+ },
130
+ [selected, compareEntities]
131
+ );
132
+ useEffect(() => {
133
+ const handleSelect = (event) => {
134
+ const row = event.payload?.row;
135
+ if (row) {
136
+ setSelected(row);
137
+ if (debug) {
138
+ console.log(`[SelectionProvider] ${event.type} received:`, row);
139
+ }
140
+ }
141
+ };
142
+ const handleDeselect = (event) => {
143
+ clearSelection();
144
+ if (debug) {
145
+ console.log(`[SelectionProvider] ${event.type} received - clearing selection`);
146
+ }
147
+ };
148
+ const unsubView = eventBus.on("UI:VIEW", handleSelect);
149
+ const unsubSelect = eventBus.on("UI:SELECT", handleSelect);
150
+ const unsubClose = eventBus.on("UI:CLOSE", handleDeselect);
151
+ const unsubDeselect = eventBus.on("UI:DESELECT", handleDeselect);
152
+ const unsubCancel = eventBus.on("UI:CANCEL", handleDeselect);
153
+ return () => {
154
+ unsubView();
155
+ unsubSelect();
156
+ unsubClose();
157
+ unsubDeselect();
158
+ unsubCancel();
159
+ };
160
+ }, [eventBus, setSelected, clearSelection, debug]);
161
+ const contextValue = {
162
+ selected,
163
+ setSelected,
164
+ clearSelection,
165
+ isSelected
166
+ };
167
+ return /* @__PURE__ */ jsx(SelectionContext.Provider, { value: contextValue, children });
168
+ }
169
+ function useSelection() {
170
+ const context = useContext(SelectionContext);
171
+ if (!context) {
172
+ throw new Error("useSelection must be used within a SelectionProvider");
173
+ }
174
+ return context;
175
+ }
176
+ function useSelectionOptional() {
177
+ const context = useContext(SelectionContext);
178
+ return context;
179
+ }
93
180
  var EntityDataContext = createContext(null);
94
181
  function EntityDataProvider({
95
182
  adapter,
96
183
  children
97
184
  }) {
98
- return React.createElement(
185
+ return React2.createElement(
99
186
  EntityDataContext.Provider,
100
187
  { value: adapter },
101
188
  children
@@ -292,92 +379,5 @@ function useEntitySuspense(entity, id) {
292
379
  return { data: null, refetch: () => {
293
380
  } };
294
381
  }
295
- var SelectionContext = createContext(null);
296
- var defaultCompareEntities = (a, b) => {
297
- if (a === b) return true;
298
- if (!a || !b) return false;
299
- if (typeof a === "object" && typeof b === "object") {
300
- const aId = a.id;
301
- const bId = b.id;
302
- return aId !== void 0 && aId === bId;
303
- }
304
- return false;
305
- };
306
- function SelectionProvider({
307
- children,
308
- debug = false,
309
- compareEntities = defaultCompareEntities
310
- }) {
311
- const eventBus = useEventBus();
312
- const [selected, setSelectedState] = useState(null);
313
- const setSelected = useCallback(
314
- (entity) => {
315
- setSelectedState(entity);
316
- if (debug) {
317
- console.log("[SelectionProvider] Selection set:", entity);
318
- }
319
- },
320
- [debug]
321
- );
322
- const clearSelection = useCallback(() => {
323
- setSelectedState(null);
324
- if (debug) {
325
- console.log("[SelectionProvider] Selection cleared");
326
- }
327
- }, [debug]);
328
- const isSelected = useCallback(
329
- (entity) => {
330
- return compareEntities(selected, entity);
331
- },
332
- [selected, compareEntities]
333
- );
334
- useEffect(() => {
335
- const handleSelect = (event) => {
336
- const row = event.payload?.row;
337
- if (row) {
338
- setSelected(row);
339
- if (debug) {
340
- console.log(`[SelectionProvider] ${event.type} received:`, row);
341
- }
342
- }
343
- };
344
- const handleDeselect = (event) => {
345
- clearSelection();
346
- if (debug) {
347
- console.log(`[SelectionProvider] ${event.type} received - clearing selection`);
348
- }
349
- };
350
- const unsubView = eventBus.on("UI:VIEW", handleSelect);
351
- const unsubSelect = eventBus.on("UI:SELECT", handleSelect);
352
- const unsubClose = eventBus.on("UI:CLOSE", handleDeselect);
353
- const unsubDeselect = eventBus.on("UI:DESELECT", handleDeselect);
354
- const unsubCancel = eventBus.on("UI:CANCEL", handleDeselect);
355
- return () => {
356
- unsubView();
357
- unsubSelect();
358
- unsubClose();
359
- unsubDeselect();
360
- unsubCancel();
361
- };
362
- }, [eventBus, setSelected, clearSelection, debug]);
363
- const contextValue = {
364
- selected,
365
- setSelected,
366
- clearSelection,
367
- isSelected
368
- };
369
- return /* @__PURE__ */ jsx(SelectionContext.Provider, { value: contextValue, children });
370
- }
371
- function useSelection() {
372
- const context = useContext(SelectionContext);
373
- if (!context) {
374
- throw new Error("useSelection must be used within a SelectionProvider");
375
- }
376
- return context;
377
- }
378
- function useSelectionOptional() {
379
- const context = useContext(SelectionContext);
380
- return context;
381
- }
382
382
 
383
383
  export { EntityDataProvider, I18nProvider, SelectionContext, SelectionProvider, createTranslate, entityDataKeys, parseQueryBinding, useEntity, useEntityDataAdapter, useEntityDetail, useEntityList, useEntityListSuspense, useEntitySuspense, useQuerySingleton, useSelection, useSelectionOptional, useTranslate };