1.13.1 • Published 2 years ago

@dylandepass/helix-web-library v1.13.1

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
2 years ago

Helix Web Library

Set of reusable classes and functions for rendering Helix pages

Status

codecov CircleCI GitHub license GitHub issues LGTM Code Quality Grade: JavaScript semantic-release

Installation

Can be added to a helix project either with by downloading the bundles directly from the releases page on github, using a cloud bundler like skypack or using npm (requires a build step).

NPM

$ npm install @dylandepass/helix-web-library

After installing, the library bundle can be added to scripts/ using the CLI:

$ npx helix-web-library install

For more updating, removing, and options, see CLI

Github Release

Download the required bundles from the releases page.

Skypack Release

Helix Web Framework ESM

Helix Web Framework ESM (Minified)

Helix Web Forms ESM

Helix Web Forms ESM (Minified)

What's included?

The two scripts included are helix-web-framework and helix-web-forms.

helix-web-framework

Includes a helper class that abstracts the decoration and loading of a helix page. This class provides various hooks and overrides for customizating the helix decoration and loading process.

Usage

import { HelixApp } from 'https://cdn.skypack.dev/@dylandepass/helix-web-library@latest/dist/helix-web-library.esm.min.js';

HelixApp.init({
  rumEnabled: true,
  rumGeneration: 'project-1',
  productionDomains: ['acme.com'],
  lcpBlocks: ['hero'],
})
  .withLoadEager(loadEager)
  .withBuildAutoBlocks((main) => {
    try {
      buildHeroBlock(main);
    } catch (error) {
      // eslint-disable-next-line no-console
      console.error('Auto Blocking failed', error);
    }
  })
  .decorate();
Builder Options

Builder configuration options

NameDescriptionExampleDefault
rumEnabledEnable RUM collection?truefalse
rumGenerationRUM generation id'project-1'undefined
productionDomainsA list of productions domains.'acme.com'[]
lcpBlocksList of blocks classes to treat as LCP'hero'[]
autoAppearShould we set the appear class on the body after LCP load? If false then client must add the appear class (document.querySelector('body').classList.add('appear');)truetrue
blocksSelectorThe CSS selector used to query blocks':scope > div > div''div.section > div > div'
lazyStylesShould lazy styles be loaded (/styles/lazy-styles.css)truefalse
favIconPath to favIcon, supports both .icon and .svg/styles/icon.ico/styles/icon.svg
iconsPathPath to icons folder/somepath/icons
enableBlockLoaderShould the block loader run? In some cases we don't want it to (i.e storybook)falsetrue
loadHeaderShould the header be loadedfalsetrue
loadFooterShould the footer be loadedfalsetrue

Lifecycle hooks

These lifecycle hooks can be used to tie custom logic into the page loading flow.

HooksDescription
withLoadEagerCalled just after main is decorated and LCP is loaded
withDecorateMainCalled after block decoration and before waitForLCP.
withLoadLazyCalled just after all blocks have been loaded (js/css)
withLoadDelayedCalled after the page load lifecycle has completed

Decoration/Loading overrides

If you need to customize the page decoration the following overrides are available.

HooksDescription
withBuildAutoBlocksAdd any logic required to build auto blocks here
withDecorateSectionsOverrides the default decorate sections logic
withDecorateBlockOverrides the default decorate block logic
withLoadHeaderOverrides the default load header logic
withLoadFooterOverrides the default load footer logic
withDecorateIconsOverrides the default decorate icons logic
withDecorateButtonsOverrides the default decorate buttons logic

For example, if you want a different decoration for your buttons you can use withDecorateButtons to override the default behaviour.

import { HelixApp } from 'https://cdn.skypack.dev/@dylandepass/helix-web-library@latest/dist/helix-web-library.esm.min.js';

HelixApp.init({
  ...
})
  ...
  .withDecorateButtons((main) => {
    // custom button decoration code
  })
  .decorate();

See the API documentation.

helix-web-forms

This is a pre-alpha and and mainly just an experiment.. Not meant for production use

Creates an HTML form based on a form definiton defined in a sheet. The form definition should be contained in the helix-default sheet. No assumptions are made on the styling of the form as is left up to the developer to style the form markup.

import { createForm } from 'helix-web-framework.esm.min.js';

export default async function decorate(block) {
  const form = block.querySelector('a[href$=".json"]');
  if (form) {
    form.replaceWith(await createForm(form.href));
  }
}

Supported form field definitions

NameDescriptionExample
FieldThe name of the field, will be set in the class name.customerName
LabelThe field labelCustomer Name
PlaceholderPlaceholder text for the fieldAcme corp
TypeThe field type. Currently supports text-field, heading, select, text-areatext-area
FormatThe input type of the field.password
MandatoryIs this a required field?x
OptionsIf field type is select, options are set hereDon't know, Yes, No
RulesBasic rules enginem, currently only supports visible{"type": "visible", "condition": {"key": "cms", "operator": "eq", "value": "AEM Sites"}}
ExtraRedirect path after submission/thank-you

CLI

Examples

Update/reinstall (overwrites existing file):

$ npx helix-web-library install --force

Remove without installing:

$ npx helix-web-library uninstall

Install to a different path (must be inside current working directory):

$ npx helix-web-library install --dir=./libs

Install Options

OptionShorthandDescriptionDefault
--dir-dInstall directory-d=./scripts
--force-fForce overwrite existing, upgrade by deleting existing library at path.
--minify-mInstall minified library

Development

New release are built automatically with every commit to main.

Build

$ npm install

Test

$ npm test

Lint

$ npm run lint
1.13.1

2 years ago

1.12.3

2 years ago

1.12.2

2 years ago

1.13.0

2 years ago

1.12.1

2 years ago

1.12.0

2 years ago

1.12.5

2 years ago

1.12.4

2 years ago

1.9.0

2 years ago

1.8.0

2 years ago

1.7.1

2 years ago

1.6.2

2 years ago

1.7.0

2 years ago

1.11.0

2 years ago

1.10.0

2 years ago

1.5.4

2 years ago

1.5.3

2 years ago

1.6.1

2 years ago

1.5.2

2 years ago

1.4.3

2 years ago

1.6.0

2 years ago

1.5.1

2 years ago

1.5.0

2 years ago

1.4.2

2 years ago

1.4.1

2 years ago

1.4.0

2 years ago

1.3.14

2 years ago

1.3.13

2 years ago

1.3.12

2 years ago

1.3.11

2 years ago

1.3.10

2 years ago

1.3.9

2 years ago

1.3.8

2 years ago

1.3.7

2 years ago

1.3.6

2 years ago

1.3.5

2 years ago

1.3.4

2 years ago

1.3.3

2 years ago

1.3.2

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.2.0

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago