Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
@github/template-parts
Advanced tools
An implementation of the TemplateInstance proposal (https://github.com/w3c/webcomponents/blob/159b1600bab02fe9cd794825440a98537d53b389/proposals/Template-Instantiation.md)
This library is designed as a "ponyfill" library that implements the design in the TemplateInstance proposed whatwg spec that has been proposed in order to address whatwg/html#2254.
This implements the minimally viable parts of the proposal, to provide something that works, but should be easy to drop if the Template Parts Proposal lands.
To reiterate the example in the above proposal, given a template such as:
<template id="foo">
<div class="foo {{y}}">{{x}} world</div>
</template>
We'd like {{x}}
and {{y}}
to be template parts, exposed as JavaScript objects which can be manipulated.
With this library, and that given template, one could implement the following:
import {TemplateInstance} from '@github/template-parts'
const tpl = new TemplateInstance(document.getElementById('some-template'), { x: 'Hello', y: 'bar'})
document.appendChild(tpl)
A TemplateInstance
instance is a subclass of DocumentFragment
- containing the cloned contents of the template. It also has an update(params: unknown): void
method - which when called will run the given "processor", with the new params
.
This library has a default "processor": propertyIdentity
which implements basic functionality of applying the params object values to the Template Parts (it is effectively part.value = params[part.expression]
)
In addition, there is a propertyIdentityOrBooleanAttribute
export which adds the capability of toggling boolean
style attributes like hidden
or input.required
.
To use the propertyIdentityOrBooleanAttribute
, import it and pass it as a third argument to the TemplateInstance
constructor:
import {TemplateInstance, propertyIdentityOrBooleanAttribute} from '@github/template-parts'
// This will simply replace `{{x}}` with `"Hello"` and `{{y}}` with `"bar"`
const tpl = new TemplateInstance(document.getElementById('foo'), { x: 'Hello', y: 'bar'})
// The `propertyIdentityOrBooleanAttribute` processor will check for `false`/`true` values which map to Template Part values that are assigned to attributes, and add/remove the attribute.
const tpl = new TemplateInstance(document.getElementById('foo'), { x: 'Hello', hidden: false}, propertyIdentityOrBooleanAttribute)
FAQs
An implementation of the TemplateInstance proposal (https://github.com/w3c/webcomponents/blob/159b1600bab02fe9cd794825440a98537d53b389/proposals/Template-Instantiation.md)
We found that @github/template-parts demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 20 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.