@jay-framework/runtime 0.5.0 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/dist/index.d.ts +7 -1
- package/dist/index.js +22 -0
- package/docs/runtime.md +52 -0
- package/package.json +5 -5
package/CHANGELOG.md
ADDED
package/dist/index.d.ts
CHANGED
|
@@ -454,6 +454,12 @@ declare const svgDynamicElement: <ViewState>(tagName: string, attributes: Attrib
|
|
|
454
454
|
declare const mathMLDynamicElement: <ViewState>(tagName: string, attributes: Attributes<ViewState>, children?: DynamicElementChildren<ViewState>, ref?: PrivateRef<ViewState, BaseJayElement<ViewState>>) => BaseJayElement<ViewState>;
|
|
455
455
|
declare function normalizeUpdates<ViewState>(updates: Array<updateFunc<ViewState>>): updateFunc<ViewState>;
|
|
456
456
|
declare function normalizeMount(mounts: Array<MountFunc>): MountFunc;
|
|
457
|
+
interface HeadLink {
|
|
458
|
+
rel: string;
|
|
459
|
+
href: string;
|
|
460
|
+
attributes?: Record<string, string>;
|
|
461
|
+
}
|
|
462
|
+
declare function injectHeadLinks(headLinks: HeadLink[]): void;
|
|
457
463
|
|
|
458
464
|
interface ContextStack<ContextType> {
|
|
459
465
|
context: ContextType;
|
|
@@ -478,4 +484,4 @@ declare class ConstructContext<ViewState> {
|
|
|
478
484
|
static withRootContext<ViewState, Refs>(viewState: ViewState, refManager: ReferencesManager, elementConstructor: () => BaseJayElement<ViewState>): JayElement<ViewState, Refs>;
|
|
479
485
|
}
|
|
480
486
|
|
|
481
|
-
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 ExtractRefs, type ExtractViewState, type ForEach, GetTrapProxy, type GlobalJayEvents, type HTMLElementCollectionProxy, type HTMLElementCollectionProxyTarget, type HTMLElementProxy, type HTMLElementProxyTarget, type HTMLNativeExec, type JayComponent, type JayComponentConstructor, type JayContract, type JayElement, type JayEvent, type JayEventHandler, type JayEventHandlerWrapper, type JayNativeEventBuilder, type JayNativeFunction, 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, booleanAttribute, childComp, conditional, createJayContext, currentConstructionContext, defaultEventWrapper, dynamicAttribute, dynamicElement, dynamicElementNS, dynamicProperty, dynamicText, element, findContext, forEach, isCondition, isForEach, mathMLDynamicElement, mathMLElement, mkUpdateCollection, noopMount, noopUpdate, normalizeMount, normalizeUpdates, restoreContext, saveContext, svgDynamicElement, svgElement, type updateFunc, useContext, withContext };
|
|
487
|
+
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 ExtractRefs, 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 JayNativeEventBuilder, type JayNativeFunction, 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, booleanAttribute, childComp, conditional, createJayContext, currentConstructionContext, defaultEventWrapper, dynamicAttribute, dynamicElement, dynamicElementNS, dynamicProperty, dynamicText, element, findContext, forEach, injectHeadLinks, isCondition, isForEach, mathMLDynamicElement, mathMLElement, mkUpdateCollection, noopMount, noopUpdate, normalizeMount, normalizeUpdates, restoreContext, saveContext, svgDynamicElement, svgElement, type updateFunc, useContext, withContext };
|
package/dist/index.js
CHANGED
|
@@ -471,6 +471,27 @@ function normalizeMount(mounts) {
|
|
|
471
471
|
return noopMount;
|
|
472
472
|
}
|
|
473
473
|
}
|
|
474
|
+
function injectHeadLinks(headLinks) {
|
|
475
|
+
const head = document.head;
|
|
476
|
+
if (!head)
|
|
477
|
+
return;
|
|
478
|
+
headLinks.forEach((linkData) => {
|
|
479
|
+
const existingLink = head.querySelector(
|
|
480
|
+
`link[href="${linkData.href}"][rel="${linkData.rel}"]`
|
|
481
|
+
);
|
|
482
|
+
if (existingLink)
|
|
483
|
+
return;
|
|
484
|
+
const link = document.createElement("link");
|
|
485
|
+
link.rel = linkData.rel;
|
|
486
|
+
link.href = linkData.href;
|
|
487
|
+
if (linkData.attributes) {
|
|
488
|
+
Object.entries(linkData.attributes).forEach(([key, value]) => {
|
|
489
|
+
link.setAttribute(key, value);
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
head.appendChild(link);
|
|
493
|
+
});
|
|
494
|
+
}
|
|
474
495
|
class PrivateRefs {
|
|
475
496
|
constructor() {
|
|
476
497
|
__publicField(this, "elements", /* @__PURE__ */ new Set());
|
|
@@ -818,6 +839,7 @@ export {
|
|
|
818
839
|
element,
|
|
819
840
|
findContext,
|
|
820
841
|
forEach,
|
|
842
|
+
injectHeadLinks,
|
|
821
843
|
isCondition,
|
|
822
844
|
isForEach,
|
|
823
845
|
mathMLDynamicElement,
|
package/docs/runtime.md
CHANGED
|
@@ -203,6 +203,58 @@ at which
|
|
|
203
203
|
|
|
204
204
|
- `propertyValue` - a function that renders the property value from the current data item
|
|
205
205
|
|
|
206
|
+
## injectHeadLinks
|
|
207
|
+
|
|
208
|
+
The `injectHeadLinks` function injects `<link>` elements into the document head. This is primarily used by the Jay compiler to automatically inject head links defined in Jay-HTML files.
|
|
209
|
+
|
|
210
|
+
The function is used in client only use cases. For jay-stack, it is expected that slowly or fast rendering will handle links and this function will not be used.
|
|
211
|
+
|
|
212
|
+
```typescript
|
|
213
|
+
import { injectHeadLinks, HeadLink } from '@jay-framework/runtime';
|
|
214
|
+
|
|
215
|
+
// Basic usage
|
|
216
|
+
injectHeadLinks([
|
|
217
|
+
{ rel: 'stylesheet', href: 'styles/main.css' },
|
|
218
|
+
{ rel: 'icon', href: '/favicon.ico' },
|
|
219
|
+
]);
|
|
220
|
+
|
|
221
|
+
// With additional attributes
|
|
222
|
+
injectHeadLinks([
|
|
223
|
+
{
|
|
224
|
+
rel: 'preconnect',
|
|
225
|
+
href: 'https://fonts.googleapis.com',
|
|
226
|
+
attributes: { crossorigin: '' },
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
rel: 'alternate',
|
|
230
|
+
href: '/feed.xml',
|
|
231
|
+
attributes: {
|
|
232
|
+
type: 'application/rss+xml',
|
|
233
|
+
title: 'RSS Feed',
|
|
234
|
+
},
|
|
235
|
+
},
|
|
236
|
+
]);
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
The `HeadLink` interface:
|
|
240
|
+
|
|
241
|
+
```typescript
|
|
242
|
+
interface HeadLink {
|
|
243
|
+
rel: string;
|
|
244
|
+
href: string;
|
|
245
|
+
attributes?: Record<string, string>;
|
|
246
|
+
}
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
**Features**:
|
|
250
|
+
|
|
251
|
+
- **Duplicate Prevention**: Automatically prevents duplicate links by checking both `href` and `rel` attributes
|
|
252
|
+
- **Attribute Support**: Supports all standard HTML link attributes via the `attributes` property
|
|
253
|
+
- **Safe Injection**: Gracefully handles missing `document.head` and other edge cases
|
|
254
|
+
- **Runtime Only**: Designed for browser environments where `document` is available
|
|
255
|
+
|
|
256
|
+
**Generated Code**: The Jay compiler automatically generates calls to `injectHeadLinks` when Jay-HTML files contain `<link>` elements in the `<head>` section.
|
|
257
|
+
|
|
206
258
|
## Jay Component
|
|
207
259
|
|
|
208
260
|
Jay Components are logic wrappers over a Jay Element, and can be coded using any coding methodology. They have to
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jay-framework/runtime",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -23,12 +23,12 @@
|
|
|
23
23
|
"test:watch": "vitest"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@jay-framework/list-compare": "
|
|
27
|
-
"@jay-framework/reactive": "
|
|
26
|
+
"@jay-framework/list-compare": "^0.5.2",
|
|
27
|
+
"@jay-framework/reactive": "^0.5.2",
|
|
28
28
|
"jsdom": "^23.2.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@jay-framework/dev-environment": "
|
|
31
|
+
"@jay-framework/dev-environment": "^0.5.2",
|
|
32
32
|
"@testing-library/jest-dom": "^6.2.0",
|
|
33
33
|
"@types/jsdom": "^21.1.6",
|
|
34
34
|
"@types/node": "^20.11.5",
|
|
@@ -40,4 +40,4 @@
|
|
|
40
40
|
"vite": "^5.0.11",
|
|
41
41
|
"vitest": "^1.2.1"
|
|
42
42
|
}
|
|
43
|
-
}
|
|
43
|
+
}
|