Package Exports
- @humany/widget-core
- @humany/widget-core/lib-esm/index.js
- @humany/widget-core/lib/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@humany/widget-core) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@humany/widget-core
Core components for the Humany widget framework.
Humany
The Humany runtime object is the main object in the widget framework and is used to create and setup implementations, as well as providing methods for accessing implementations and widgets in the runtime.
Humany.create(): Humany (static)
Creates a new Humany instance using default settings.
Humany.createFromGlobal(globalHumany: any): Humany (static)
Creates a new Humany instance from a global object which can be either a temporary object created by the Humany embed script or an existing Humany instance. This factory method is used to support eager runtime configurations in a setup when the Humany runtime is loaded asynchronously.
humany.widgets.find(selector: WidgetSelector): WidgetData
Returns the first widget that matches the provided selector.
humany.widgets.query(selector: WidgetSelector): WidgetData[]
Returns all widgets that matches the provided selector.
humany.widgets.all(): WidgetData[]
Returns all widgets in the the runtime.
humany.implementations.find(selector: ImplementationSelector): Implementation
Returns the first implementation that matches the provided selector.
humany.implementations.query(selector: ImplementationSelector): Implementation[]
Returns all implementations that matches the provided selector.
humany.implementations.all(): Implementation[]
Returns all implementations in the the runtime.
Widget
Base class for Humany widgets.
Plugin
Base class for Humany plugins.
loadImplementation(humany: Humany, url: string): Promise<Implementation>
Loads an implementation configuration from the Humany service and creates an instance of the implementation on the provided Humany object.
bootstrap(implementation: Implementation, (config: Configurator) => void): Promise
Bootstraps the provided implementation by scanning the document for trigger elements associated to the widgets in the implementation.
Example
The following example sets up a remote Humany implementation containing a Floating widget and bootstraps it using the default bootstrapping extensions (with support for "trigger elements").
import { Humany, loadImplementation, bootstrap } from '@humany/widget-core';
import { FloatingWidget } from '@humany/widget-types-floating';
(async () => {
// create the runtime
const humany = window.humany = Humany.createFromGlobal(window.humany);
// load implementation
const implementation = await loadImplementation(
humany,
'https://sandbox.humany.net/floating-demo',
);
// bootstrap implementation
bootstrap(implementation, (config) => {
// register widget-types
config.types.register('@humany/floating-widget', FloatingWidget);
config.ready(() => console.info('Implementation has been bootstrapped'));
});
})();