@vef-framework/core 1.0.135 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README +15 -0
- package/dist/cjs/api/client.cjs +171 -0
- package/dist/cjs/api/constants.cjs +13 -0
- package/dist/cjs/api/helpers.cjs +12 -0
- package/dist/cjs/api/index.cjs +14 -0
- package/dist/cjs/auth/helpers.cjs +19 -0
- package/dist/cjs/auth/index.cjs +10 -0
- package/dist/cjs/common/index.cjs +3 -0
- package/dist/cjs/context/api-client.cjs +25 -0
- package/dist/cjs/context/app.cjs +15 -0
- package/dist/cjs/context/context-selector.cjs +65 -0
- package/dist/cjs/context/disabled.cjs +15 -0
- package/dist/cjs/context/index.cjs +19 -0
- package/dist/cjs/dnd/index.cjs +102 -0
- package/dist/cjs/http/client.cjs +445 -0
- package/dist/cjs/http/errors.cjs +23 -0
- package/dist/cjs/http/helpers.cjs +17 -0
- package/dist/cjs/http/index.cjs +17 -0
- package/dist/cjs/immer/index.cjs +40 -0
- package/dist/cjs/index.cjs +306 -0
- package/dist/cjs/motion/features.cjs +13 -0
- package/dist/cjs/motion/index.cjs +48 -0
- package/dist/cjs/motion/motion-provider.cjs +29 -0
- package/dist/cjs/query/constants.cjs +8 -0
- package/dist/cjs/query/helpers.cjs +67 -0
- package/dist/cjs/query/hooks.cjs +52 -0
- package/dist/cjs/query/index.cjs +20 -0
- package/dist/cjs/state/index.cjs +41 -0
- package/dist/cjs/state-machine/index.cjs +35 -0
- package/dist/cjs/store/bound.cjs +42 -0
- package/dist/cjs/store/index.cjs +20 -0
- package/dist/cjs/store/unbound.cjs +74 -0
- package/dist/cjs/store/use-deep.cjs +17 -0
- package/dist/es/api/client.js +167 -0
- package/dist/es/api/constants.js +8 -0
- package/dist/es/api/helpers.js +8 -0
- package/dist/es/api/index.js +4 -0
- package/dist/es/auth/helpers.js +15 -0
- package/dist/es/auth/index.js +2 -0
- package/dist/es/common/index.js +1 -0
- package/dist/es/context/api-client.js +20 -0
- package/dist/es/context/app.js +10 -0
- package/dist/es/context/context-selector.js +61 -0
- package/dist/es/context/disabled.js +10 -0
- package/dist/es/context/index.js +5 -0
- package/dist/es/dnd/index.js +7 -0
- package/dist/es/http/client.js +439 -0
- package/dist/es/http/errors.js +19 -0
- package/dist/es/http/helpers.js +12 -0
- package/dist/es/http/index.js +4 -0
- package/dist/es/immer/index.js +8 -0
- package/dist/es/index.js +43 -0
- package/dist/es/motion/features.js +2 -0
- package/dist/es/motion/index.js +5 -0
- package/dist/es/motion/motion-provider.js +25 -0
- package/dist/es/query/constants.js +4 -0
- package/dist/es/query/helpers.js +60 -0
- package/dist/es/query/hooks.js +27 -0
- package/dist/es/query/index.js +4 -0
- package/dist/es/state/index.js +2 -0
- package/dist/es/state-machine/index.js +12 -0
- package/dist/es/store/bound.js +37 -0
- package/dist/es/store/index.js +5 -0
- package/dist/es/store/unbound.js +70 -0
- package/dist/es/store/use-deep.js +13 -0
- package/dist/types/api/client.d.ts +75 -0
- package/dist/types/api/constants.d.ts +8 -0
- package/dist/types/api/helpers.d.ts +9 -0
- package/dist/types/api/index.d.ts +4 -0
- package/dist/types/api/types.d.ts +48 -0
- package/dist/types/auth/helpers.d.ts +11 -0
- package/dist/types/auth/index.d.ts +2 -0
- package/dist/types/auth/types.d.ts +1 -0
- package/dist/types/common/index.d.ts +1 -0
- package/dist/types/common/types.d.ts +95 -0
- package/dist/types/context/api-client.d.ts +18 -0
- package/dist/types/context/app.d.ts +4 -0
- package/dist/types/context/context-selector.d.ts +44 -0
- package/dist/types/context/disabled.d.ts +9 -0
- package/dist/types/context/index.d.ts +5 -0
- package/dist/types/context/types.d.ts +27 -0
- package/dist/types/dnd/index.d.ts +6 -0
- package/dist/types/http/client.d.ts +144 -0
- package/dist/types/http/errors.d.ts +14 -0
- package/dist/types/http/helpers.d.ts +17 -0
- package/dist/types/http/index.d.ts +4 -0
- package/dist/types/http/types.d.ts +101 -0
- package/dist/types/immer/index.d.ts +2 -0
- package/dist/types/index.d.ts +14 -0
- package/dist/types/motion/features.d.ts +1 -0
- package/dist/types/motion/index.d.ts +4 -0
- package/dist/types/motion/motion-provider.d.ts +5 -0
- package/dist/types/query/constants.d.ts +1 -0
- package/dist/types/query/helpers.d.ts +10 -0
- package/dist/types/query/hooks.d.ts +66 -0
- package/dist/types/query/index.d.ts +4 -0
- package/dist/types/query/types.d.ts +51 -0
- package/dist/types/state/index.d.ts +1 -0
- package/dist/types/state-machine/index.d.ts +14 -0
- package/dist/types/store/bound.d.ts +28 -0
- package/dist/types/store/index.d.ts +5 -0
- package/dist/types/store/types.d.ts +50 -0
- package/dist/types/store/unbound.d.ts +26 -0
- package/dist/types/store/use-deep.d.ts +7 -0
- package/package.json +59 -37
- package/README.md +0 -25
- package/cjs/api/api-client.cjs +0 -2
- package/cjs/api/api-context.cjs +0 -2
- package/cjs/api/index.cjs +0 -2
- package/cjs/api/query-client.cjs +0 -2
- package/cjs/api/request-client.cjs +0 -2
- package/cjs/auth/auth-context.cjs +0 -2
- package/cjs/auth/index.cjs +0 -2
- package/cjs/expr/compiler.cjs +0 -2
- package/cjs/expr/helpers.cjs +0 -2
- package/cjs/index.cjs +0 -2
- package/cjs/middleware/dispatcher.cjs +0 -2
- package/esm/api/api-client.js +0 -2
- package/esm/api/api-context.js +0 -2
- package/esm/api/index.js +0 -2
- package/esm/api/query-client.js +0 -2
- package/esm/api/request-client.js +0 -2
- package/esm/auth/auth-context.js +0 -2
- package/esm/auth/index.js +0 -2
- package/esm/expr/compiler.js +0 -2
- package/esm/expr/helpers.js +0 -2
- package/esm/index.js +0 -2
- package/esm/middleware/dispatcher.js +0 -2
- package/types/api/api-client.d.ts +0 -203
- package/types/api/api-context.d.ts +0 -167
- package/types/api/index.d.ts +0 -3
- package/types/api/query-client.d.ts +0 -27
- package/types/api/request-client.d.ts +0 -95
- package/types/auth/auth-context.d.ts +0 -29
- package/types/auth/index.d.ts +0 -1
- package/types/expr/compiler.d.ts +0 -35
- package/types/expr/helpers.d.ts +0 -58
- package/types/index.d.ts +0 -3
- package/types/middleware/dispatcher.d.ts +0 -22
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/*! @vef-framework/core v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:30.112Z */
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
5
|
+
|
|
6
|
+
const jsxRuntime = require('@emotion/react/jsx-runtime');
|
|
7
|
+
const shared = require('@vef-framework/shared');
|
|
8
|
+
const react$1 = require('motion/react');
|
|
9
|
+
const react = require('react');
|
|
10
|
+
const zustand = require('zustand');
|
|
11
|
+
const middleware = require('zustand/middleware');
|
|
12
|
+
const immer = require('zustand/middleware/immer');
|
|
13
|
+
|
|
14
|
+
const contextCache = /* @__PURE__ */ new Map();
|
|
15
|
+
function createComponentStore(name, initializer) {
|
|
16
|
+
const contextKey = `${name}StoreContext`;
|
|
17
|
+
let Context = contextCache.get(contextKey);
|
|
18
|
+
if (!Context) {
|
|
19
|
+
Context = react.createContext(null);
|
|
20
|
+
Context.displayName = contextKey;
|
|
21
|
+
contextCache.set(contextKey, Context);
|
|
22
|
+
}
|
|
23
|
+
function StoreProvider(props) {
|
|
24
|
+
const { children } = props;
|
|
25
|
+
const storeRef = react.useRef(null);
|
|
26
|
+
const storeInitializedRef = react.useRef(false);
|
|
27
|
+
const latestInitialStateRef = react.useRef(void 0);
|
|
28
|
+
latestInitialStateRef.current = props.initialState;
|
|
29
|
+
if (!storeRef.current || !storeInitializedRef.current) {
|
|
30
|
+
storeRef.current = zustand.createStore()(
|
|
31
|
+
middleware.subscribeWithSelector(
|
|
32
|
+
immer.immer(initializer)
|
|
33
|
+
)
|
|
34
|
+
);
|
|
35
|
+
storeInitializedRef.current = true;
|
|
36
|
+
}
|
|
37
|
+
react$1.useIsomorphicLayoutEffect(() => {
|
|
38
|
+
if (!shared.isPlainObject(latestInitialStateRef.current)) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if (storeRef.current) {
|
|
42
|
+
storeRef.current.setState((state) => {
|
|
43
|
+
shared.mergeWith(
|
|
44
|
+
state,
|
|
45
|
+
latestInitialStateRef.current,
|
|
46
|
+
true
|
|
47
|
+
);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}, []);
|
|
51
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Context, { value: storeRef.current, children });
|
|
52
|
+
}
|
|
53
|
+
function useStoreApi() {
|
|
54
|
+
const store = react.use(Context);
|
|
55
|
+
if (!store) {
|
|
56
|
+
const isDev = process.env.NODE_ENV === "development";
|
|
57
|
+
const errorMessage = `${name}Store is not found in the React context, please check if the store is wrapped in a ${name}StoreProvider`;
|
|
58
|
+
const devHint = isDev ? "\n\nDev hint: If you're seeing this error after hot reload, it might be a React Fast Refresh issue. Try refreshing the page." : "";
|
|
59
|
+
throw new Error(errorMessage + devHint);
|
|
60
|
+
}
|
|
61
|
+
return store;
|
|
62
|
+
}
|
|
63
|
+
function useStore(selector) {
|
|
64
|
+
const store = useStoreApi();
|
|
65
|
+
return zustand.useStore(store, selector);
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
StoreProvider,
|
|
69
|
+
useStoreApi,
|
|
70
|
+
useStore
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
exports.createComponentStore = createComponentStore;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/*! @vef-framework/core v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:30.112Z */
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
5
|
+
|
|
6
|
+
const shared = require('@vef-framework/shared');
|
|
7
|
+
const react = require('react');
|
|
8
|
+
|
|
9
|
+
function useDeep(selector) {
|
|
10
|
+
const prevRef = react.useRef(null);
|
|
11
|
+
return (state) => {
|
|
12
|
+
const next = selector(state);
|
|
13
|
+
return shared.isDeepEqual(prevRef.current, next) ? prevRef.current : prevRef.current = next;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
exports.useDeep = useDeep;
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/*! @vef-framework/core v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:30.112Z */
|
|
2
|
+
import { isFunction } from '@vef-framework/shared';
|
|
3
|
+
import '../http/index.js';
|
|
4
|
+
import '../query/index.js';
|
|
5
|
+
import { QUERY_CLIENT, PROXIED_METHODS } from './constants.js';
|
|
6
|
+
import { createHttpClient } from '../http/helpers.js';
|
|
7
|
+
import { createQueryClient } from '../query/helpers.js';
|
|
8
|
+
|
|
9
|
+
class ApiClient {
|
|
10
|
+
/**
|
|
11
|
+
* The HTTP client.
|
|
12
|
+
*/
|
|
13
|
+
#httpClient;
|
|
14
|
+
/**
|
|
15
|
+
* The query client.
|
|
16
|
+
*/
|
|
17
|
+
#queryClient;
|
|
18
|
+
/**
|
|
19
|
+
* The current signal.
|
|
20
|
+
*/
|
|
21
|
+
#currentSignal;
|
|
22
|
+
/**
|
|
23
|
+
* The query client.
|
|
24
|
+
*/
|
|
25
|
+
get [QUERY_CLIENT]() {
|
|
26
|
+
return this.#queryClient;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Creates a new API client.
|
|
30
|
+
*
|
|
31
|
+
* @param options - The options for the API client.
|
|
32
|
+
*/
|
|
33
|
+
constructor(options) {
|
|
34
|
+
const {
|
|
35
|
+
http,
|
|
36
|
+
query
|
|
37
|
+
} = options;
|
|
38
|
+
this.#httpClient = createHttpClient(http);
|
|
39
|
+
this.#queryClient = createQueryClient(query);
|
|
40
|
+
const proxyCache = /* @__PURE__ */ new Map();
|
|
41
|
+
this.#httpClient = new Proxy(this.#httpClient, {
|
|
42
|
+
get: (target, prop, receiver) => {
|
|
43
|
+
const value = Reflect.get(target, prop, receiver);
|
|
44
|
+
if (!isFunction(value)) {
|
|
45
|
+
return value;
|
|
46
|
+
}
|
|
47
|
+
if (!proxyCache.has(prop)) {
|
|
48
|
+
if (PROXIED_METHODS.includes(prop)) {
|
|
49
|
+
proxyCache.set(prop, (url, options2) => value.apply(
|
|
50
|
+
target,
|
|
51
|
+
[
|
|
52
|
+
url,
|
|
53
|
+
{
|
|
54
|
+
...options2,
|
|
55
|
+
signal: this.#currentSignal
|
|
56
|
+
}
|
|
57
|
+
]
|
|
58
|
+
));
|
|
59
|
+
} else {
|
|
60
|
+
proxyCache.set(prop, (...args) => value.apply(target, args));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return proxyCache.get(prop);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Creates a new query function.
|
|
69
|
+
*
|
|
70
|
+
* @param key - The key of the query function.
|
|
71
|
+
* @param factory - The factory function.
|
|
72
|
+
* @returns The query function.
|
|
73
|
+
*/
|
|
74
|
+
createQueryFn(key, factory) {
|
|
75
|
+
const queryFn = factory(this.#httpClient);
|
|
76
|
+
const wrapperFn = (context) => {
|
|
77
|
+
const {
|
|
78
|
+
queryKey,
|
|
79
|
+
signal,
|
|
80
|
+
pageParam,
|
|
81
|
+
meta
|
|
82
|
+
} = context;
|
|
83
|
+
const [, params] = queryKey;
|
|
84
|
+
try {
|
|
85
|
+
this.#currentSignal = signal;
|
|
86
|
+
return queryFn(
|
|
87
|
+
params,
|
|
88
|
+
pageParam,
|
|
89
|
+
meta
|
|
90
|
+
);
|
|
91
|
+
} finally {
|
|
92
|
+
this.#currentSignal = void 0;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
Object.defineProperty(wrapperFn, "key", {
|
|
96
|
+
value: key,
|
|
97
|
+
configurable: false,
|
|
98
|
+
writable: false,
|
|
99
|
+
enumerable: false
|
|
100
|
+
});
|
|
101
|
+
return wrapperFn;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Creates a new mutation function.
|
|
105
|
+
*
|
|
106
|
+
* @param key - The key of the mutation function.
|
|
107
|
+
* @param factory - The factory function.
|
|
108
|
+
* @returns The mutation function.
|
|
109
|
+
*/
|
|
110
|
+
createMutationFn(key, factory) {
|
|
111
|
+
const mutationFn = factory(this.#httpClient);
|
|
112
|
+
const wrapperFn = (params) => mutationFn(params);
|
|
113
|
+
Object.defineProperty(wrapperFn, "key", {
|
|
114
|
+
value: key,
|
|
115
|
+
configurable: false,
|
|
116
|
+
writable: false,
|
|
117
|
+
enumerable: false
|
|
118
|
+
});
|
|
119
|
+
return wrapperFn;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Fetches a query.
|
|
123
|
+
*
|
|
124
|
+
* @param options - The options for the query.
|
|
125
|
+
* @returns The result of the query.
|
|
126
|
+
*/
|
|
127
|
+
async fetchQuery(options) {
|
|
128
|
+
return await this.#queryClient.fetchQuery(options);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Prefetches a query and stores the result in cache.
|
|
132
|
+
*
|
|
133
|
+
* @param options - The options for the query.
|
|
134
|
+
* @returns A promise that resolves when the prefetch is complete.
|
|
135
|
+
*/
|
|
136
|
+
async prefetchQuery(options) {
|
|
137
|
+
return await this.#queryClient.prefetchQuery(options);
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Executes a mutation outside of React components.
|
|
141
|
+
*
|
|
142
|
+
* This method allows you to execute mutations imperatively without using the `useMutation` hook.
|
|
143
|
+
* Useful for scenarios like login flows, event handlers, or any code outside React components.
|
|
144
|
+
*
|
|
145
|
+
* @template TData - The type of data returned by the mutation
|
|
146
|
+
* @template TParams - The type of parameters passed to the mutation function
|
|
147
|
+
* @template TOnMutateResult - The type of result returned by onMutate callback
|
|
148
|
+
*
|
|
149
|
+
* @param options - The mutation options including mutationFn, onSuccess, onError, etc.
|
|
150
|
+
* @param variables - The variables to pass to the mutation function. Omit this argument when the mutation does not require parameters.
|
|
151
|
+
* @remarks This reuses TanStack Query's imperative mutation execution so lifecycle callbacks (onMutate, onSuccess, etc.) still fire.
|
|
152
|
+
* @returns A promise that resolves with the mutation result
|
|
153
|
+
*/
|
|
154
|
+
async executeMutation({
|
|
155
|
+
mutationFn,
|
|
156
|
+
params,
|
|
157
|
+
...options
|
|
158
|
+
}) {
|
|
159
|
+
return await this.#queryClient.getMutationCache().build(this.#queryClient, {
|
|
160
|
+
mutationKey: [mutationFn.key],
|
|
161
|
+
mutationFn,
|
|
162
|
+
...options
|
|
163
|
+
}).execute(params);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export { ApiClient };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/*! @vef-framework/core v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:30.112Z */
|
|
2
|
+
import '../query/index.js';
|
|
3
|
+
import { QUERY_CLIENT_KEY } from '../query/constants.js';
|
|
4
|
+
|
|
5
|
+
const PROXIED_METHODS = ["get", "post", "put", "delete", "upload", "download"];
|
|
6
|
+
const QUERY_CLIENT = Symbol.for(QUERY_CLIENT_KEY);
|
|
7
|
+
|
|
8
|
+
export { PROXIED_METHODS, QUERY_CLIENT };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/*! @vef-framework/core v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:30.112Z */
|
|
2
|
+
import { isNullish, isString } from '@vef-framework/shared';
|
|
3
|
+
|
|
4
|
+
function checkPermission(hasPermission, permTokens, checkMode = "any") {
|
|
5
|
+
if (isNullish(permTokens)) {
|
|
6
|
+
return true;
|
|
7
|
+
}
|
|
8
|
+
const normalizedPermTokens = isString(permTokens) ? [permTokens] : permTokens;
|
|
9
|
+
if (checkMode === "any") {
|
|
10
|
+
return normalizedPermTokens.some((token) => hasPermission(token));
|
|
11
|
+
}
|
|
12
|
+
return normalizedPermTokens.every((token) => hasPermission(token));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { checkPermission };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/*! @vef-framework/core v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:30.112Z */
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/*! @vef-framework/core v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:30.112Z */
|
|
2
|
+
import { jsx } from '@emotion/react/jsx-runtime';
|
|
3
|
+
import { QueryClientProvider } from '@tanstack/react-query';
|
|
4
|
+
import { createContext, use } from 'react';
|
|
5
|
+
import '../api/index.js';
|
|
6
|
+
import { QUERY_CLIENT } from '../api/constants.js';
|
|
7
|
+
|
|
8
|
+
const Context = createContext(null);
|
|
9
|
+
function ApiClientProvider({ value, children }) {
|
|
10
|
+
return /* @__PURE__ */ jsx(Context, { value, children: /* @__PURE__ */ jsx(QueryClientProvider, { client: value[QUERY_CLIENT], children }) });
|
|
11
|
+
}
|
|
12
|
+
function useApiClient() {
|
|
13
|
+
const apiClient = use(Context);
|
|
14
|
+
if (!apiClient) {
|
|
15
|
+
throw new Error("No 'ApiClientContext' found in the React app, please use 'ApiClientProvider' to wrap your app.");
|
|
16
|
+
}
|
|
17
|
+
return apiClient;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { ApiClientProvider, useApiClient };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/*! @vef-framework/core v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:30.112Z */
|
|
2
|
+
import { createContext, use } from 'react';
|
|
3
|
+
|
|
4
|
+
const Context = createContext({});
|
|
5
|
+
const AppContextProvider = Context.Provider;
|
|
6
|
+
function useAppContext() {
|
|
7
|
+
return use(Context);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export { AppContextProvider, useAppContext };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/*! @vef-framework/core v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:30.112Z */
|
|
2
|
+
import { jsx } from '@emotion/react/jsx-runtime';
|
|
3
|
+
import { isFunction } from '@vef-framework/shared';
|
|
4
|
+
import { createContext, useState, useEffect, use, useSyncExternalStore } from 'react';
|
|
5
|
+
|
|
6
|
+
function createContextWithSelector(defaultValue) {
|
|
7
|
+
const Context = createContext(createStore(defaultValue));
|
|
8
|
+
function Provider({ value, children }) {
|
|
9
|
+
const [store] = useState(() => createStore(value));
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
if (!Object.is(store.value, value)) {
|
|
12
|
+
store.value = value;
|
|
13
|
+
store.notify();
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
return /* @__PURE__ */ jsx(Context, { value: store, children });
|
|
17
|
+
}
|
|
18
|
+
Provider.displayName = "SelectorContextProvider";
|
|
19
|
+
function useContext(selector) {
|
|
20
|
+
const store = use(Context);
|
|
21
|
+
return useSyncExternalStore(
|
|
22
|
+
store.subscribe,
|
|
23
|
+
// Get current value, applying selector if provided
|
|
24
|
+
() => isFunction(selector) ? selector(store.value) : store.value,
|
|
25
|
+
// Server-side snapshot (same as client-side for consistency)
|
|
26
|
+
() => isFunction(selector) ? selector(store.value) : store.value
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
Provider,
|
|
31
|
+
useContext
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function createStore(value) {
|
|
35
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
36
|
+
return {
|
|
37
|
+
value,
|
|
38
|
+
/**
|
|
39
|
+
* Subscribe to store changes
|
|
40
|
+
*
|
|
41
|
+
* @param listener - Function to call when store value changes
|
|
42
|
+
* @returns Unsubscribe function
|
|
43
|
+
*/
|
|
44
|
+
subscribe: (listener) => {
|
|
45
|
+
listeners.add(listener);
|
|
46
|
+
return () => {
|
|
47
|
+
listeners.delete(listener);
|
|
48
|
+
};
|
|
49
|
+
},
|
|
50
|
+
/**
|
|
51
|
+
* Notify all subscribers that the value has changed
|
|
52
|
+
*/
|
|
53
|
+
notify: () => {
|
|
54
|
+
for (const listener of listeners) {
|
|
55
|
+
listener();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export { createContextWithSelector };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/*! @vef-framework/core v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:30.112Z */
|
|
2
|
+
import { createContext, use } from 'react';
|
|
3
|
+
|
|
4
|
+
const DisabledContext = createContext(false);
|
|
5
|
+
function useDisabled() {
|
|
6
|
+
return use(DisabledContext);
|
|
7
|
+
}
|
|
8
|
+
const DisabledProvider = DisabledContext.Provider;
|
|
9
|
+
|
|
10
|
+
export { DisabledProvider, useDisabled };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/*! @vef-framework/core v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:30.112Z */
|
|
2
|
+
export { ApiClientProvider, useApiClient } from './api-client.js';
|
|
3
|
+
export { AppContextProvider, useAppContext } from './app.js';
|
|
4
|
+
export { createContextWithSelector } from './context-selector.js';
|
|
5
|
+
export { DisabledProvider, useDisabled } from './disabled.js';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/*! @vef-framework/core v2.0.0 made with ❤️ by Venus | 2025-11-25T10:06:30.112Z */
|
|
2
|
+
export { AxisModifier, RestrictToHorizontalAxis, RestrictToVerticalAxis, SnapModifier, restrictShapeToBoundingRectangle } from '@dnd-kit/abstract/modifiers';
|
|
3
|
+
export { RestrictToElement, RestrictToWindow } from '@dnd-kit/dom/modifiers';
|
|
4
|
+
export { arrayMove as moveArrayItem, move as moveDragItem, arraySwap as swapArrayItem, swap as swapDragItem } from '@dnd-kit/helpers';
|
|
5
|
+
export { DragDropProvider, DragOverlay, KeyboardSensor, PointerSensor, useDragDropMonitor, useDraggable, useDroppable } from '@dnd-kit/react';
|
|
6
|
+
export { useSortable } from '@dnd-kit/react/sortable';
|
|
7
|
+
export { DragDropContext, Draggable, Droppable } from '@hello-pangea/dnd';
|