micro-lc web component
Web component
micro-lc in itself is a web component, registered with tag micro-lc
. It can be
sourced from CDN, or installed as a
npm package.
- CDN
- npm package
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>CDN example</title>
<script async type="module" src="https://cdn.jsdelivr.net/npm/@micro-lc/orchestrator@latest/dist/micro-lc.production.js"></script>
</head>
<body>
<micro-lc></micro-lc>
</body>
</html>
import React from 'react'
import MicroLc from '@micro-lc/orchestrator'
function App() {
return (<micro-lc></micro-lc>)
}
customElements.define('micro-lc', MicroLc)
export default App
Development and production mode
micro-lc web component comes in two flavors: development and production.
Development variant is injected into the
CustomElementRegistry
with a larger bundle
size (~700 KB) since it includes an instance of the Ajv JSON schema validator to check if
configurations provided to the web components are valid. Development variant also provides feedback on errors via
browser console
.
To reduce the bundle size, production variant lacks all previously mentioned features and shrinks down to ~180 KB.
Properties & attributes
Property | Attribute | Type | Default | Description |
---|---|---|---|---|
config | - | Configuration | Default configuration | micro-lc configuration. |
configSrc | config-src | string | - | URL from which configuration can be fetched. |
fallbackLanguage | fallback-language | string | - | Language tag used as fallback. |
- | disable-shadow-dom | boolean | false | Whether micro-lc should be in Shadow DOM. |
- | root-id | string | __micro_lc | Mount point <div> id. |
- | disable-styling | boolean | false | Disable mount point preset styling. |
Attributes disable-shadow-dom
, root-id
, and disable-styling
are not observed, meaning their initial value is
the only one that matters and no changes are listened to.
Configuration
Everything concerning the structure of your application – from layout to content, from general settings to global imports – is contained in micro-lc configuration.
This configuration can be directly supplied to micro-lc web component through property config
,
programmatically set with API method setcurrentconfig
, or
sourced through property configSrc
(or mirrored attribute config-src
) in JSON or YAML format.
YAML is clearer and easier to read and write, but bring a computational and bundle size (~38 KB) overhead, since it requires an extra step to be compiled back to JSON.
For this reason, we recommend YAML for development and JSON for production. A YAML to JSON converter is available in the Playground section.
Practically speaking, micro-lc configuration is an object with the following structure (each key is explained in details below):
interface Config {
$schema?: string
version?: 2
settings?: Settings
shared?: Shared
importmap?: Importmap
layout?: Layout
applications?: Applications
}
Key $schema
can be used to reference micro-lc configuration
JSON schema to greatly ease
the writing process by constantly validating the JSON or YAML content against it.
Default configuration
If no configuration is provided micro-lc uses the following default configuration:
version: 2
settings:
defaultUrl: ./
layout:
content:
tag: slot
settings
- Type:
Object
Global micro-lc settings.
4xx
- Type:
Object
- Optional
Configuration for custom error pages linked to client errors.
Example:
- YAML
- JSON
settings:
4xx:
401:
integrationMode: parcel
entry: https://my-static-server/custom-401-error-page.html
{
"settings": {
"4xx": {
"401": {
"integrationMode": "parcel",
"entry": "https://my-static-server/custom-401-error-page.html"
}
}
}
}
5xx
- Type:
Object
- Optional
Configuration for custom error pages linked to server errors.
Example:
- YAML
- JSON
settings:
5xx:
502:
integrationMode: parcel
entry: https://my-static-server/custom-502-error-page.html
{
"settings": {
"5xx": {
"502": {
"integrationMode": "parcel",
"entry": "https://my-static-server/custom-502-error-page.html"
}
}
}
}
composerUri
- Type:
string
- Optional
URI from which composer can be sourced, if a different implementation from default micro-lc one is needed.
Example:
- YAML
- JSON
settings:
composerUri: https://my-static-server/my-custom-composer.js
{
"settings": {
"composerUri": "https://my-static-server/my-custom-composer.js"
}
}
mountPoint
- Type:
Object
- Optional
Custom application mount point configuration.
Example:
- YAML
- JSON
settings:
mountPoint:
tag: div
attributes:
id: custom-mount-point
{
"settings": {
"mountPoint": {
"tag": "div",
"attributes": {
"id": "custom-mount-point"
}
}
}
}
mountPointSelector
- Type:
string
- Optional
Query selector to plugins mounting DOM element.
Example:
- YAML
- JSON
settings:
mountPointSelector: "#custom-mount-point"
{
"settings": {
"mountPointSelector": "#custom-mount-point"
}
}
defaultUrl
- Type:
string
- Default:
./
Landing URL. If it does not correspond to any configured application, 404 error page will be rendered.
Example:
- YAML
- JSON
settings:
defaultUrl: ./home
{
"settings": {
"defaultUrl": "./home"
}
}
shared
- Type:
interface Shared {
properties?: Record<string, unknown>
}
Properties injected by micro-lc into all registered parcels, custom error pages, and composed DOM elements.
Parcel applications and custom error pages of type parcel can access shared properties in lifecycle methods. Web components of composed applications, error pages of type compose, and constructed layout will find shared properties as interpolated properties.
Example:
- YAML
- JSON
shared:
properties:
client-key: some_client_key
{
"shared": {
"properties": {
"client-key": "some_client_key"
}
}
importmap
- Type:
Object
Global import map.
Example:
- YAML
- JSON
importmap:
imports:
react: https://esm.sh/react@next
react-dom: https://esm.sh/react-dom@next
scopes:
https://esm.sh/react-dom@next:
/client: https://esm.sh/react-dom@next/client
{
"importmap": {
"imports": {
"react": "https://esm.sh/react@next",
"react-dom": "https://esm.sh/react-dom@next"
},
"scopes": {
"https://esm.sh/react-dom@next": {
"/client": "https://esm.sh/react-dom@next/client"
}
}
}
}
layout
- Type:
Object
- Default:
layout:
content:
tag: slot
Application layout DOM configuration.
Example:
- YAML
- JSON
layout:
content:
- tag: div
attributes:
class: layout-container
content:
- tag: div
attributes:
class: side-bar
- tag: slot
{
"layout": {
"content": [
{
"tag": "div",
"attributes": {
"class": "layout-container",
"content": [
{
"tag": "div",
"attributes": {
"class": "side-bar"
}
},
{
"tag": "slot"
}
]
}
}
]
}
}
applications
- Type:
Object
Map of mounted applications.
Example:
- YAML
- JSON
applications:
home:
integrationMode: parcel
entry: https://my-static-server/home-parcel.html
route: ./home
{
"applications": {
"home": {
"integrationMode": "parcel",
"entry": "https://my-static-server/home-parcel.html",
"route": "./home"
}
}
}