@jay-framework/runtime 0.9.0 → 0.10.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.
- package/dist/index.d.ts +30 -1
- package/dist/index.js +18 -0
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -502,6 +502,35 @@ interface ContextStack<ContextType> {
|
|
|
502
502
|
marker: ContextMarker<ContextType>;
|
|
503
503
|
parent?: ContextStack<any>;
|
|
504
504
|
}
|
|
505
|
+
/**
|
|
506
|
+
* Registers a global context that will be available to all components.
|
|
507
|
+
* Global contexts are checked after the context stack, so component-provided
|
|
508
|
+
* contexts can override global ones.
|
|
509
|
+
*
|
|
510
|
+
* @param marker - The context marker created with createJayContext()
|
|
511
|
+
* @param context - The context value to register
|
|
512
|
+
*
|
|
513
|
+
* @example
|
|
514
|
+
* ```typescript
|
|
515
|
+
* // In lib/init.ts (using makeJayInit pattern)
|
|
516
|
+
* export const init = makeJayInit()
|
|
517
|
+
* .withServer(() => ({ itemsPerPage: 10 }))
|
|
518
|
+
* .withClient((serverData) => {
|
|
519
|
+
* registerGlobalContext(APP_CONFIG_CONTEXT, serverData);
|
|
520
|
+
* });
|
|
521
|
+
* ```
|
|
522
|
+
*/
|
|
523
|
+
declare function registerGlobalContext<ContextType>(marker: ContextMarker<ContextType>, context: ContextType): void;
|
|
524
|
+
/**
|
|
525
|
+
* Clears all registered global contexts.
|
|
526
|
+
* Internal API for testing and hot reload.
|
|
527
|
+
*/
|
|
528
|
+
declare function clearGlobalContextRegistry(): void;
|
|
529
|
+
/**
|
|
530
|
+
* Gets a global context by marker.
|
|
531
|
+
* Internal API used by findContext.
|
|
532
|
+
*/
|
|
533
|
+
declare function useGlobalContext<ContextType>(marker: ContextMarker<ContextType>): ContextType | undefined;
|
|
505
534
|
declare function createJayContext<ContextType = unknown>(): ContextMarker<ContextType>;
|
|
506
535
|
declare function withContext<ContextType, Returns>(marker: ContextMarker<ContextType>, context: ContextType, callback: () => Returns): Returns;
|
|
507
536
|
declare function useContext<ContextType>(marker: ContextMarker<ContextType>): ContextType;
|
|
@@ -521,4 +550,4 @@ declare class ConstructContext<ViewState> {
|
|
|
521
550
|
static withRootContext<ViewState, Refs>(viewState: ViewState, refManager: ReferencesManager, elementConstructor: () => BaseJayElement<ViewState>): JayElement<ViewState, Refs>;
|
|
522
551
|
}
|
|
523
552
|
|
|
524
|
-
export { type Attribute, type Attributes, type BaseJayElement, BaseReferencesManager, type ComponentCollectionProxy, ComponentCollectionRefImpl, type ComponentProxy, ComponentRefImpl, ComponentRefsImpl, type Conditional, ConstructContext, type ContextMarker, type Coordinate, type DynamicAttributeOrProperty, EVENT_TRAP, type ElementFrom, type EventEmitter, type EventTypeFrom, type ExtractFastViewState, type ExtractInteractiveViewState, type ExtractRefs, type ExtractSlowViewState, type ExtractViewState, type ForEach, GetTrapProxy, type GlobalJayEvents, type HTMLElementCollectionProxy, type HTMLElementCollectionProxyTarget, type HTMLElementProxy, type HTMLElementProxyTarget, type HTMLNativeExec, type HeadLink, type JayComponent, type JayComponentConstructor, type JayContract, type JayElement, type JayEvent, type JayEventHandler, type JayEventHandlerWrapper, type JayLog, type JayNativeEventBuilder, type JayNativeFunction, LogType, type ManagedRefConstructor, ManagedRefType, type ManagedRefs, type MapEventEmitterViewState, type MountFunc, type OnlyEventEmitters, type PreRenderElement, type PrivateRef, type PrivateRefConstructor, PrivateRefs, type PropsFrom, ReferencesManager, type RenderElement, type RenderElementOptions, type TextElement, type ViewStateFrom, type When, WhenRole, type WithData, booleanAttribute, childComp, conditional, createJayContext, currentConstructionContext, defaultEventWrapper, dynamicAttribute, dynamicElement, dynamicElementNS, dynamicProperty, dynamicText, element, findContext, forEach, injectHeadLinks, isCondition, isForEach, isWhen, isWithData, jayLog, mathMLDynamicElement, mathMLElement, mkUpdateCollection, noop, noopMount, noopUpdate, normalizeMount, normalizeUpdates, pending, rejected, resolved, restoreContext, saveContext, svgDynamicElement, svgElement, type updateFunc, useContext, withContext, withData };
|
|
553
|
+
export { type Attribute, type Attributes, type BaseJayElement, BaseReferencesManager, type ComponentCollectionProxy, ComponentCollectionRefImpl, type ComponentProxy, ComponentRefImpl, ComponentRefsImpl, type Conditional, ConstructContext, type ContextMarker, type Coordinate, type DynamicAttributeOrProperty, EVENT_TRAP, type ElementFrom, type EventEmitter, type EventTypeFrom, type ExtractFastViewState, type ExtractInteractiveViewState, type ExtractRefs, type ExtractSlowViewState, type ExtractViewState, type ForEach, GetTrapProxy, type GlobalJayEvents, type HTMLElementCollectionProxy, type HTMLElementCollectionProxyTarget, type HTMLElementProxy, type HTMLElementProxyTarget, type HTMLNativeExec, type HeadLink, type JayComponent, type JayComponentConstructor, type JayContract, type JayElement, type JayEvent, type JayEventHandler, type JayEventHandlerWrapper, type JayLog, type JayNativeEventBuilder, type JayNativeFunction, LogType, type ManagedRefConstructor, ManagedRefType, type ManagedRefs, type MapEventEmitterViewState, type MountFunc, type OnlyEventEmitters, type PreRenderElement, type PrivateRef, type PrivateRefConstructor, PrivateRefs, type PropsFrom, ReferencesManager, type RenderElement, type RenderElementOptions, type TextElement, type ViewStateFrom, type When, WhenRole, type WithData, booleanAttribute, childComp, clearGlobalContextRegistry, conditional, createJayContext, currentConstructionContext, defaultEventWrapper, dynamicAttribute, dynamicElement, dynamicElementNS, dynamicProperty, dynamicText, element, findContext, forEach, injectHeadLinks, isCondition, isForEach, isWhen, isWithData, jayLog, mathMLDynamicElement, mathMLElement, mkUpdateCollection, noop, noopMount, noopUpdate, normalizeMount, normalizeUpdates, pending, registerGlobalContext, rejected, resolved, restoreContext, saveContext, svgDynamicElement, svgElement, type updateFunc, useContext, useGlobalContext, withContext, withData };
|
package/dist/index.js
CHANGED
|
@@ -97,6 +97,16 @@ let currentContext = void 0;
|
|
|
97
97
|
function NewContextStack(context, marker, parent) {
|
|
98
98
|
return { context, marker, parent };
|
|
99
99
|
}
|
|
100
|
+
const globalContextRegistry = /* @__PURE__ */ new Map();
|
|
101
|
+
function registerGlobalContext(marker, context) {
|
|
102
|
+
globalContextRegistry.set(marker, context);
|
|
103
|
+
}
|
|
104
|
+
function clearGlobalContextRegistry() {
|
|
105
|
+
globalContextRegistry.clear();
|
|
106
|
+
}
|
|
107
|
+
function useGlobalContext(marker) {
|
|
108
|
+
return globalContextRegistry.get(marker);
|
|
109
|
+
}
|
|
100
110
|
function createJayContext() {
|
|
101
111
|
return Symbol();
|
|
102
112
|
}
|
|
@@ -122,6 +132,11 @@ function findContext(predicate) {
|
|
|
122
132
|
return aContext.context;
|
|
123
133
|
aContext = aContext.parent;
|
|
124
134
|
}
|
|
135
|
+
for (const [marker, context] of globalContextRegistry.entries()) {
|
|
136
|
+
if (predicate(marker)) {
|
|
137
|
+
return context;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
125
140
|
return void 0;
|
|
126
141
|
}
|
|
127
142
|
function saveContext() {
|
|
@@ -983,6 +998,7 @@ export {
|
|
|
983
998
|
WhenRole,
|
|
984
999
|
booleanAttribute,
|
|
985
1000
|
childComp,
|
|
1001
|
+
clearGlobalContextRegistry,
|
|
986
1002
|
conditional,
|
|
987
1003
|
createJayContext,
|
|
988
1004
|
currentConstructionContext,
|
|
@@ -1010,6 +1026,7 @@ export {
|
|
|
1010
1026
|
normalizeMount,
|
|
1011
1027
|
normalizeUpdates,
|
|
1012
1028
|
pending,
|
|
1029
|
+
registerGlobalContext,
|
|
1013
1030
|
rejected,
|
|
1014
1031
|
resolved,
|
|
1015
1032
|
restoreContext,
|
|
@@ -1017,6 +1034,7 @@ export {
|
|
|
1017
1034
|
svgDynamicElement,
|
|
1018
1035
|
svgElement,
|
|
1019
1036
|
useContext,
|
|
1037
|
+
useGlobalContext,
|
|
1020
1038
|
withContext,
|
|
1021
1039
|
withData
|
|
1022
1040
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jay-framework/runtime",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -23,11 +23,11 @@
|
|
|
23
23
|
"test:watch": "vitest"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@jay-framework/list-compare": "^0.
|
|
27
|
-
"@jay-framework/reactive": "^0.
|
|
26
|
+
"@jay-framework/list-compare": "^0.10.0",
|
|
27
|
+
"@jay-framework/reactive": "^0.10.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@jay-framework/dev-environment": "^0.
|
|
30
|
+
"@jay-framework/dev-environment": "^0.10.0",
|
|
31
31
|
"@testing-library/jest-dom": "^6.2.0",
|
|
32
32
|
"@types/jsdom": "^21.1.6",
|
|
33
33
|
"@types/node": "^20.11.5",
|