@empathyco/x-components 3.0.0-alpha.221 → 3.0.0-alpha.222

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 CHANGED
@@ -3,6 +3,18 @@
3
3
  All notable changes to this project will be documented in this file. See
4
4
  [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [3.0.0-alpha.222](https://github.com/empathyco/x/compare/@empathyco/x-components@3.0.0-alpha.221...@empathyco/x-components@3.0.0-alpha.222) (2022-11-10)
7
+
8
+ ### Features
9
+
10
+ - **x-plugin:** Add function as possible value of `domElement` in InstallXOptions.(#836)
11
+ ([99a96ef](https://github.com/empathyco/x/commit/99a96ef2303f27b656835253203bc73758a337ae))
12
+
13
+ # Change Log
14
+
15
+ All notable changes to this project will be documented in this file. See
16
+ [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
17
+
6
18
  ## [3.0.0-alpha.221](https://github.com/empathyco/x/compare/@empathyco/x-components@3.0.0-alpha.220...@empathyco/x-components@3.0.0-alpha.221) (2022-11-10)
7
19
 
8
20
  ### Features
@@ -2866,6 +2866,10 @@
2866
2866
  .x-picture--zoom .x-picture__image:hover {
2867
2867
  transform: scale(var(--x-number-zoom-scale-picture));
2868
2868
  }
2869
+ :root {
2870
+ --x-number-zoom-scale-picture: 1.1;
2871
+ --x-number-zoom-duration-picture: 0.3s;
2872
+ }
2869
2873
  .x-progress-bar {
2870
2874
  display: inline-block;
2871
2875
  overflow: hidden;
@@ -7288,8 +7292,3 @@
7288
7292
  .x-normal-case {
7289
7293
  text-transform: none;
7290
7294
  }
7291
-
7292
- :root {
7293
- --x-number-zoom-scale-picture: 1.1;
7294
- --x-number-zoom-duration-picture: 0.3s;
7295
- }
@@ -4,10 +4,10 @@
4
4
 
5
5
  ## InstallXOptions.domElement property
6
6
 
7
- An Element \| string to indicate the HTML element that will contain the Vue application. If string selector is passed and the element doesn't exits, the [XInstaller](./x-components.xinstaller.md) will create it.
7
+ An Element \| string \| function to indicate the HTML element that will contain the Vue application. If it isn't passed, the [XInstaller](./x-components.xinstaller.md) will create the target element.
8
8
 
9
9
  <b>Signature:</b>
10
10
 
11
11
  ```typescript
12
- domElement?: Element | string;
12
+ domElement?: Element | string | ((snippetConfig: NormalisedSnippetConfig) => Element | string);
13
13
  ```
@@ -20,7 +20,7 @@ export interface InstallXOptions<API extends XAPI = XAPI> extends XPluginOptions
20
20
  | [api?](./x-components.installxoptions.api.md) | API \| false | <i>(Optional)</i> The API to expose globally. If is not passed the default [BaseXAPI](./x-components.basexapi.md) will be used. If a <code>false</code> value is passed then the API is not created. |
21
21
  | [app?](./x-components.installxoptions.app.md) | VueConstructor \| ComponentOptions&lt;Vue&gt; | <i>(Optional)</i> The Vue component used as root of the application. If it is not passed, no Vue Application is initialized, only plugin installed. |
22
22
  | [bus?](./x-components.installxoptions.bus.md) | [XBus](./x-components.xbus.md) | <i>(Optional)</i> The [XBus](./x-components.xbus.md) used in the [XPlugin](./x-components.xplugin.md)<!-- -->. If not passed an instance of [BaseXBus](./x-components.basexbus.md) will be used. |
23
- | [domElement?](./x-components.installxoptions.domelement.md) | Element \| string | <i>(Optional)</i> An Element \| string to indicate the HTML element that will contain the Vue application. If string selector is passed and the element doesn't exits, the [XInstaller](./x-components.xinstaller.md) will create it. |
23
+ | [domElement?](./x-components.installxoptions.domelement.md) | Element \| string \| ((snippetConfig: [NormalisedSnippetConfig](./x-components.normalisedsnippetconfig.md)<!-- -->) =&gt; Element \| string) | <i>(Optional)</i> An Element \| string \| function to indicate the HTML element that will contain the Vue application. If it isn't passed, the [XInstaller](./x-components.xinstaller.md) will create the target element. |
24
24
  | [onCreateApp?](./x-components.installxoptions.oncreateapp.md) | (app: Vue) =&gt; void | <i>(Optional)</i> Callback to invoke after instantiating the app. |
25
25
  | [plugin?](./x-components.installxoptions.plugin.md) | PluginObject&lt;[XPluginOptions](./x-components.xpluginoptions.md)<!-- -->&gt; | <i>(Optional)</i> The XPlugin which will be installed. If not passed, an instance of [XPlugin](./x-components.xplugin.md) will be installed. |
26
26
  | [vue?](./x-components.installxoptions.vue.md) | VueConstructor | <i>(Optional)</i> The Vue instance used to install the plugin and to create the Application. If not passed the default Vue instance is used. This can be useful to use the <code>localVue</code> in the unit tests. |
@@ -1,4 +1,4 @@
1
- import { forEach } from '@empathyco/x-utils';
1
+ import { isFunction, forEach } from '@empathyco/x-utils';
2
2
  import Vue from 'vue';
3
3
  import { BaseXBus } from '../../plugins/x-bus.js';
4
4
  import { XPlugin } from '../../plugins/x-plugin.js';
@@ -255,29 +255,30 @@ class XInstaller {
255
255
  return snippetConfig;
256
256
  }
257
257
  /**
258
- * It returns the HTML element to mount the Vue Application. If the `domElement` parameter in the
259
- * {@link InstallXOptions} is an Element or a string, then it is used. If it is
260
- * not present then a new <div> Element is created and append to the body to be used.
258
+ * It returns the HTML element to mount the Vue Application. If the `domElement` parameter in
259
+ * the {@link InstallXOptions} is an Element or an element selector, then this will be used.
260
+ * The `domElement` can also be a function with the {@link SnippetConfig} as parameter which
261
+ * returns an Element or element selector to use.
262
+ * If it is not present, a new <div> Element is created and appended to the body.
261
263
  *
262
- * @param elementOrSelector - String or Element used to mount the Vue App.
264
+ * @param domElement - {@link InstallXOptions.domElement | Element, string or function} Used
265
+ * to mount the Vue Application.
263
266
  *
264
- * @returns The Element to use as mounting point for the Vue App.
267
+ * @returns The Element to use as mounting target for the Vue Application.
265
268
  * @internal
266
269
  */
267
- getMountingTarget(elementOrSelector) {
268
- if (typeof elementOrSelector === 'string') {
269
- const target = document.querySelector(elementOrSelector);
270
+ getMountingTarget(domElement) {
271
+ if (isFunction(domElement)) {
272
+ domElement = domElement(this.snippetConfig);
273
+ }
274
+ if (typeof domElement === 'string') {
275
+ const target = document.querySelector(domElement);
270
276
  if (!target) {
271
- throw Error(`XComponents app couldn't be mounted: Element "${elementOrSelector}" couldn't be found`);
277
+ throw Error(`XComponents app couldn't be mounted: Element "${domElement}" couldn't be found`);
272
278
  }
273
279
  return target;
274
280
  }
275
- else if (elementOrSelector !== undefined) {
276
- return elementOrSelector;
277
- }
278
- else {
279
- return document.body.appendChild(document.createElement('div'));
280
- }
281
+ return domElement ?? document.body.appendChild(document.createElement('div'));
281
282
  }
282
283
  /**
283
284
  * It updates all the provided properties from the current snippet config.
@@ -1 +1 @@
1
- {"version":3,"file":"x-installer.js","sources":["../../../../src/x-installer/x-installer/x-installer.ts"],"sourcesContent":["import { forEach } from '@empathyco/x-utils';\nimport Vue, { PluginObject, VueConstructor } from 'vue';\nimport { BaseXBus } from '../../plugins/x-bus';\nimport { XBus } from '../../plugins/x-bus.types';\nimport { XPlugin } from '../../plugins/x-plugin';\nimport { XPluginOptions } from '../../plugins/x-plugin.types';\nimport { NormalisedSnippetConfig, SnippetConfig, XAPI } from '../api/api.types';\nimport { BaseXAPI } from '../api/base-api';\nimport { InitWrapper, InstallXOptions, VueConstructorPartialArgument } from './types';\n\ndeclare global {\n interface Window {\n InterfaceX?: XAPI;\n initX?: (() => SnippetConfig) | SnippetConfig;\n }\n}\n\n/**\n * The purpose of this class is to offer a quick way to initialize the XComponents in a setup\n * project. It allows to receive all the options in {@link InstallXOptions} which is an extension\n * of {@link XPluginOptions} with all the options for the plugin and some options more.\n *\n * This class does multiple things:\n * 1. Install the {@link XPlugin} with the {@link XPluginOptions}.\n * 2. Creates the public {@link XAPI} and add it to global window.\n * 3. Creates the Vue Application for the customer project.\n *\n * The steps 2 & 3 are optional and depends on the options passed in {@link InstallXOptions}.\n *\n * @example The way to use this class is the next:\n * 1. Create the installer passing in the {@link InstallXOptions}. This only save the options:\n *\n * ```\n * const installer = new XInstaller(installXOptions)\n * ```\n *\n * 2. Initialize passing the {@link SnippetConfig}. This installs the plugin and creates the App.\n * There are 3 different ways to do this:\n *\n * 2.1 Using the created installer:\n *\n * ```\n * installer.init(snippetConfig)\n * ```\n *\n * 2.2 If the API option is enabled (`createAPI` is `true` in {@link InstallXOptions}, or\n * is not present as the default value is `true`) then this init step can be done with\n * the Public API:\n *\n * ```\n * window.InterfaceX.init(snippetConfig)\n * ```\n *\n * 2.3 When the script of the project build is loaded it searches for a global `initX`\n * variable that the customer must have in their website. This variable can be a\n * function that returns the {@link SnippetConfig} or an object that contains the\n * {@link SnippetConfig} itself:\n *\n * ```\n * window.initX = function() {\n * return {\n * instance,\n * env,\n * scope,\n * lang,\n * uiLang,\n * currency,\n * consent,\n * documentDirection\n * };\n * };\n * ```\n *\n * ```\n * window.initX = {\n * instance,\n * env,\n * scope,\n * lang,\n * uiLang,\n * currency,\n * consent,\n * documentDirection\n * };\n * ```\n *\n * @public\n */\nexport class XInstaller {\n private api?: XAPI;\n\n /**\n * The configuration coming from the snippet {@link SnippetConfig}.\n *\n * @internal\n */\n protected snippetConfig?: NormalisedSnippetConfig;\n\n /**\n * Receives the {@link InstallXOptions} and merges it with the default fallback options. Also\n * creates the public {@link XAPI}.\n *\n * @remarks Auto initializes the Vue application if window.initX is defined as a function or\n * object specifying the {@link SnippetConfig | snippet config}.\n *\n *\n * @param options - The {@link InstallXOptions}.\n *\n * @public\n */\n public constructor(protected readonly options: InstallXOptions) {\n this.createAPI();\n }\n\n /**\n * Creates the public {@link XAPI} using the `api` option from {@link InstallXOptions}. If this\n * `api` option is not passed, then a default {@link BaseXAPI} is created. To disable the API\n * creation the value `false` must be passed in the `api` option.\n *\n * @internal\n */\n protected createAPI(): void {\n const { api } = this.options;\n if (api !== false) {\n this.api = api ?? new BaseXAPI();\n this.api.setInitCallback(this.init.bind(this));\n this.api.setSnippetConfigCallback(this.updateSnippetConfig.bind(this));\n window.InterfaceX = this.api;\n }\n }\n\n /**\n * Retrieves the {@link SnippetConfig | snippet config} it is defined in the window.initX.\n *\n * @returns The snippet config if it is defined or undefined otherwise.\n *\n * @internal\n */\n private retrieveSnippetConfig(): SnippetConfig | undefined {\n if (typeof window.initX === 'function') {\n return window.initX();\n } else if (typeof window.initX === 'object') {\n return window.initX;\n }\n }\n\n /**\n * Receives the {@link SnippetConfig | snippet config} or retrieves it from window.initX and\n * installs the plugin and initializes the Vue application.\n *\n * @param snippetConfig - The {@link SnippetConfig} that receives from snippet integration.\n *\n * @returns If {@link SnippetConfig | snippet config} is passed or configured in window.initX,\n * returns an object with the {@link XAPI}, the {@link XBus}, the {@link XPlugin} and the Vue App\n * used in the application. Else, a rejected promise is returned.\n *\n * @public\n */\n init(snippetConfig: SnippetConfig): Promise<InitWrapper>;\n init(): Promise<InitWrapper | void>;\n async init(snippetConfig = this.retrieveSnippetConfig()): Promise<InitWrapper | void> {\n if (snippetConfig) {\n this.snippetConfig = this.normaliseSnippetConfig(snippetConfig);\n const bus = this.createBus();\n const pluginOptions = this.getPluginOptions();\n const plugin = this.installPlugin(pluginOptions, bus);\n const extraPlugins = await this.installExtraPlugins(bus);\n const app = this.createApp(extraPlugins);\n this.api?.setBus(bus);\n\n return {\n api: this.api,\n app,\n bus,\n plugin\n };\n }\n\n return Promise.resolve();\n }\n\n /**\n * Creates the {@link XPluginOptions} object.\n *\n * @returns The {@link XPluginOptions} object.\n *\n * @internal\n */\n protected getPluginOptions(): XPluginOptions {\n const { adapter, store, initialXModules, xModules, __PRIVATE__xModules } = this.options;\n return {\n adapter,\n store,\n xModules,\n initialXModules,\n __PRIVATE__xModules\n };\n }\n\n /**\n * This method returns the bus instance to be used in the {@link XPlugin} and in the {@link XAPI}.\n * It returns the `bus` parameter in the {@link InstallXOptions} or if not provided, then\n * creates a new instance of {@link BaseXBus}.\n *\n * @returns XBus - The bus instance.\n *\n * @internal\n */\n protected createBus(): XBus {\n return this.options.bus ?? new BaseXBus();\n }\n\n /**\n * This method returns the VueConstructor to use to create the App instance.\n * It returns the `vue` parameter in the {@link InstallXOptions} or if not provided, then\n * returns the default Vue.\n *\n * @remarks The purpose of this option is mainly the testing. In a test we can use this option\n * to pass the local vue instance created by `createLocalVue` method.\n *\n * @returns VueConstructor - The vue constructor to create the App instance.\n *\n * @internal\n */\n protected getVue(): VueConstructor {\n return this.options.vue ?? Vue;\n }\n\n /**\n * Creates and install the Vue Plugin. If `plugin` parameter is passed in the\n * {@link InstallXOptions}, then it is used. If not, then a new instance of {@link XPlugin} is\n * created and installed.\n *\n * @param pluginOptions - The {@link XPluginOptions} to passed as parameter to the install method\n * of the plugin.\n * @param bus - The {@link XBus} to be used to create the XPlugin.\n *\n * @returns PluginObject<XPluginOption> - The plugin instance.\n * @internal\n */\n protected installPlugin(pluginOptions: XPluginOptions, bus: XBus): PluginObject<XPluginOptions> {\n const plugin = this.options.plugin ?? new XPlugin(bus);\n const vue = this.getVue();\n vue.use(plugin, pluginOptions);\n return plugin;\n }\n\n /**\n * Install more plugins to Vue defined by the user.\n *\n * @param bus - The events bus used in the application.\n * @returns The arguments from the plugins installation to be used in Vue's constructor.\n * @internal\n */\n protected installExtraPlugins(bus: XBus): Promise<VueConstructorPartialArgument> {\n const vue = this.getVue();\n return Promise.resolve(\n this.options.installExtraPlugins?.({ vue, snippet: this.snippetConfig!, bus })\n );\n }\n\n /**\n * In the case that the `app` parameter is present in the {@link InstallXOptions}, then a new Vue\n * application is created using that app.\n *\n * @param extraPlugins - Vue plugins initialisation data.\n * @returns The Created Vue application or undefined if not created.\n *\n * @internal\n */\n protected createApp(extraPlugins: VueConstructorPartialArgument): Vue | undefined {\n if (this.options.app !== undefined) {\n const vue = this.getVue();\n const app = new vue({\n ...extraPlugins,\n ...this.options.vueOptions,\n provide: {\n snippetConfig: (this.snippetConfig = vue.observable(this.snippetConfig))\n },\n store: this.options.store,\n el: this.getMountingTarget(this.options.domElement),\n render: h => h(this.options.app)\n });\n this.options.onCreateApp?.(app);\n return app;\n }\n }\n\n protected normaliseSnippetConfig(snippetConfig: SnippetConfig): NormalisedSnippetConfig;\n protected normaliseSnippetConfig(snippetConfig: Partial<SnippetConfig>): Partial<SnippetConfig>;\n /**\n * Transforms the snippet configuration.\n * - If `lang` is provided and `uiLang` is not, it sets `uiLang=lang`.\n *\n * @param snippetConfig - The snippet config to normalise.\n * @returns The normalised version of the given snippet config.\n * @internal\n */\n protected normaliseSnippetConfig(\n snippetConfig: SnippetConfig | Partial<SnippetConfig>\n ): NormalisedSnippetConfig | Partial<SnippetConfig> {\n if (snippetConfig.lang) {\n snippetConfig.uiLang ??= snippetConfig.lang;\n }\n return snippetConfig;\n }\n\n /**\n * It returns the HTML element to mount the Vue Application. If the `domElement` parameter in the\n * {@link InstallXOptions} is an Element or a string, then it is used. If it is\n * not present then a new <div> Element is created and append to the body to be used.\n *\n * @param elementOrSelector - String or Element used to mount the Vue App.\n *\n * @returns The Element to use as mounting point for the Vue App.\n * @internal\n */\n protected getMountingTarget(elementOrSelector?: string | Element): Element {\n if (typeof elementOrSelector === 'string') {\n const target = document.querySelector(elementOrSelector);\n if (!target) {\n throw Error(\n `XComponents app couldn't be mounted: Element \"${elementOrSelector}\" couldn't be found`\n );\n }\n return target;\n } else if (elementOrSelector !== undefined) {\n return elementOrSelector;\n } else {\n return document.body.appendChild(document.createElement('div'));\n }\n }\n\n /**\n * It updates all the provided properties from the current snippet config.\n *\n * @param newSnippetConfig - All the properties to be updated in the {@link SnippetConfig}.\n *\n * @internal\n */\n protected updateSnippetConfig(newSnippetConfig: Partial<SnippetConfig>): void {\n if (!this.snippetConfig) {\n return;\n }\n forEach(this.normaliseSnippetConfig(newSnippetConfig), (name, value) => {\n this.getVue().set(this.snippetConfig!, name, value);\n });\n }\n}\n"],"names":[],"mappings":";;;;;;AAiBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAuEa,UAAU;;;;;;;;;;;;;IAsBrB,YAAsC,OAAwB;QAAxB,YAAO,GAAP,OAAO,CAAiB;QAC5D,IAAI,CAAC,SAAS,EAAE,CAAC;KAClB;;;;;;;;IASS,SAAS;QACjB,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC;QAC7B,IAAI,GAAG,KAAK,KAAK,EAAE;YACjB,IAAI,CAAC,GAAG,GAA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BAAsB,CAAC,gBAAgB,CAAC,EAAE,CAAC,IAAI,EAAE,KAAK;YACjE,IAAI,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,aAAc,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;SACrD,CAAC,CAAC;KACJ;;;;;"}
1
+ {"version":3,"file":"x-installer.js","sources":["../../../../src/x-installer/x-installer/x-installer.ts"],"sourcesContent":["import { forEach, isFunction } from '@empathyco/x-utils';\nimport Vue, { PluginObject, VueConstructor } from 'vue';\nimport { BaseXBus } from '../../plugins/x-bus';\nimport { XBus } from '../../plugins/x-bus.types';\nimport { XPlugin } from '../../plugins/x-plugin';\nimport { XPluginOptions } from '../../plugins/x-plugin.types';\nimport { NormalisedSnippetConfig, SnippetConfig, XAPI } from '../api/api.types';\nimport { BaseXAPI } from '../api/base-api';\nimport { InitWrapper, InstallXOptions, VueConstructorPartialArgument } from './types';\n\ndeclare global {\n interface Window {\n InterfaceX?: XAPI;\n initX?: (() => SnippetConfig) | SnippetConfig;\n }\n}\n\n/**\n * The purpose of this class is to offer a quick way to initialize the XComponents in a setup\n * project. It allows to receive all the options in {@link InstallXOptions} which is an extension\n * of {@link XPluginOptions} with all the options for the plugin and some options more.\n *\n * This class does multiple things:\n * 1. Install the {@link XPlugin} with the {@link XPluginOptions}.\n * 2. Creates the public {@link XAPI} and add it to global window.\n * 3. Creates the Vue Application for the customer project.\n *\n * The steps 2 & 3 are optional and depends on the options passed in {@link InstallXOptions}.\n *\n * @example The way to use this class is the next:\n * 1. Create the installer passing in the {@link InstallXOptions}. This only save the options:\n *\n * ```\n * const installer = new XInstaller(installXOptions)\n * ```\n *\n * 2. Initialize passing the {@link SnippetConfig}. This installs the plugin and creates the App.\n * There are 3 different ways to do this:\n *\n * 2.1 Using the created installer:\n *\n * ```\n * installer.init(snippetConfig)\n * ```\n *\n * 2.2 If the API option is enabled (`createAPI` is `true` in {@link InstallXOptions}, or\n * is not present as the default value is `true`) then this init step can be done with\n * the Public API:\n *\n * ```\n * window.InterfaceX.init(snippetConfig)\n * ```\n *\n * 2.3 When the script of the project build is loaded it searches for a global `initX`\n * variable that the customer must have in their website. This variable can be a\n * function that returns the {@link SnippetConfig} or an object that contains the\n * {@link SnippetConfig} itself:\n *\n * ```\n * window.initX = function() {\n * return {\n * instance,\n * env,\n * scope,\n * lang,\n * uiLang,\n * currency,\n * consent,\n * documentDirection\n * };\n * };\n * ```\n *\n * ```\n * window.initX = {\n * instance,\n * env,\n * scope,\n * lang,\n * uiLang,\n * currency,\n * consent,\n * documentDirection\n * };\n * ```\n *\n * @public\n */\nexport class XInstaller {\n private api?: XAPI;\n\n /**\n * The configuration coming from the snippet {@link SnippetConfig}.\n *\n * @internal\n */\n protected snippetConfig?: NormalisedSnippetConfig;\n\n /**\n * Receives the {@link InstallXOptions} and merges it with the default fallback options. Also\n * creates the public {@link XAPI}.\n *\n * @remarks Auto initializes the Vue application if window.initX is defined as a function or\n * object specifying the {@link SnippetConfig | snippet config}.\n *\n *\n * @param options - The {@link InstallXOptions}.\n *\n * @public\n */\n public constructor(protected readonly options: InstallXOptions) {\n this.createAPI();\n }\n\n /**\n * Creates the public {@link XAPI} using the `api` option from {@link InstallXOptions}. If this\n * `api` option is not passed, then a default {@link BaseXAPI} is created. To disable the API\n * creation the value `false` must be passed in the `api` option.\n *\n * @internal\n */\n protected createAPI(): void {\n const { api } = this.options;\n if (api !== false) {\n this.api = api ?? new BaseXAPI();\n this.api.setInitCallback(this.init.bind(this));\n this.api.setSnippetConfigCallback(this.updateSnippetConfig.bind(this));\n window.InterfaceX = this.api;\n }\n }\n\n /**\n * Retrieves the {@link SnippetConfig | snippet config} it is defined in the window.initX.\n *\n * @returns The snippet config if it is defined or undefined otherwise.\n *\n * @internal\n */\n private retrieveSnippetConfig(): SnippetConfig | undefined {\n if (typeof window.initX === 'function') {\n return window.initX();\n } else if (typeof window.initX === 'object') {\n return window.initX;\n }\n }\n\n /**\n * Receives the {@link SnippetConfig | snippet config} or retrieves it from window.initX and\n * installs the plugin and initializes the Vue application.\n *\n * @param snippetConfig - The {@link SnippetConfig} that receives from snippet integration.\n *\n * @returns If {@link SnippetConfig | snippet config} is passed or configured in window.initX,\n * returns an object with the {@link XAPI}, the {@link XBus}, the {@link XPlugin} and the Vue App\n * used in the application. Else, a rejected promise is returned.\n *\n * @public\n */\n init(snippetConfig: SnippetConfig): Promise<InitWrapper>;\n init(): Promise<InitWrapper | void>;\n async init(snippetConfig = this.retrieveSnippetConfig()): Promise<InitWrapper | void> {\n if (snippetConfig) {\n this.snippetConfig = this.normaliseSnippetConfig(snippetConfig);\n const bus = this.createBus();\n const pluginOptions = this.getPluginOptions();\n const plugin = this.installPlugin(pluginOptions, bus);\n const extraPlugins = await this.installExtraPlugins(bus);\n const app = this.createApp(extraPlugins);\n this.api?.setBus(bus);\n\n return {\n api: this.api,\n app,\n bus,\n plugin\n };\n }\n\n return Promise.resolve();\n }\n\n /**\n * Creates the {@link XPluginOptions} object.\n *\n * @returns The {@link XPluginOptions} object.\n *\n * @internal\n */\n protected getPluginOptions(): XPluginOptions {\n const { adapter, store, initialXModules, xModules, __PRIVATE__xModules } = this.options;\n return {\n adapter,\n store,\n xModules,\n initialXModules,\n __PRIVATE__xModules\n };\n }\n\n /**\n * This method returns the bus instance to be used in the {@link XPlugin} and in the {@link XAPI}.\n * It returns the `bus` parameter in the {@link InstallXOptions} or if not provided, then\n * creates a new instance of {@link BaseXBus}.\n *\n * @returns XBus - The bus instance.\n *\n * @internal\n */\n protected createBus(): XBus {\n return this.options.bus ?? new BaseXBus();\n }\n\n /**\n * This method returns the VueConstructor to use to create the App instance.\n * It returns the `vue` parameter in the {@link InstallXOptions} or if not provided, then\n * returns the default Vue.\n *\n * @remarks The purpose of this option is mainly the testing. In a test we can use this option\n * to pass the local vue instance created by `createLocalVue` method.\n *\n * @returns VueConstructor - The vue constructor to create the App instance.\n *\n * @internal\n */\n protected getVue(): VueConstructor {\n return this.options.vue ?? Vue;\n }\n\n /**\n * Creates and install the Vue Plugin. If `plugin` parameter is passed in the\n * {@link InstallXOptions}, then it is used. If not, then a new instance of {@link XPlugin} is\n * created and installed.\n *\n * @param pluginOptions - The {@link XPluginOptions} to passed as parameter to the install method\n * of the plugin.\n * @param bus - The {@link XBus} to be used to create the XPlugin.\n *\n * @returns PluginObject<XPluginOption> - The plugin instance.\n * @internal\n */\n protected installPlugin(pluginOptions: XPluginOptions, bus: XBus): PluginObject<XPluginOptions> {\n const plugin = this.options.plugin ?? new XPlugin(bus);\n const vue = this.getVue();\n vue.use(plugin, pluginOptions);\n return plugin;\n }\n\n /**\n * Install more plugins to Vue defined by the user.\n *\n * @param bus - The events bus used in the application.\n * @returns The arguments from the plugins installation to be used in Vue's constructor.\n * @internal\n */\n protected installExtraPlugins(bus: XBus): Promise<VueConstructorPartialArgument> {\n const vue = this.getVue();\n return Promise.resolve(\n this.options.installExtraPlugins?.({ vue, snippet: this.snippetConfig!, bus })\n );\n }\n\n /**\n * In the case that the `app` parameter is present in the {@link InstallXOptions}, then a new Vue\n * application is created using that app.\n *\n * @param extraPlugins - Vue plugins initialisation data.\n * @returns The Created Vue application or undefined if not created.\n *\n * @internal\n */\n protected createApp(extraPlugins: VueConstructorPartialArgument): Vue | undefined {\n if (this.options.app !== undefined) {\n const vue = this.getVue();\n const app = new vue({\n ...extraPlugins,\n ...this.options.vueOptions,\n provide: {\n snippetConfig: (this.snippetConfig = vue.observable(this.snippetConfig))\n },\n store: this.options.store,\n el: this.getMountingTarget(this.options.domElement),\n render: h => h(this.options.app)\n });\n this.options.onCreateApp?.(app);\n return app;\n }\n }\n\n protected normaliseSnippetConfig(snippetConfig: SnippetConfig): NormalisedSnippetConfig;\n protected normaliseSnippetConfig(snippetConfig: Partial<SnippetConfig>): Partial<SnippetConfig>;\n /**\n * Transforms the snippet configuration.\n * - If `lang` is provided and `uiLang` is not, it sets `uiLang=lang`.\n *\n * @param snippetConfig - The snippet config to normalise.\n * @returns The normalised version of the given snippet config.\n * @internal\n */\n protected normaliseSnippetConfig(\n snippetConfig: SnippetConfig | Partial<SnippetConfig>\n ): NormalisedSnippetConfig | Partial<SnippetConfig> {\n if (snippetConfig.lang) {\n snippetConfig.uiLang ??= snippetConfig.lang;\n }\n return snippetConfig;\n }\n\n /**\n * It returns the HTML element to mount the Vue Application. If the `domElement` parameter in\n * the {@link InstallXOptions} is an Element or an element selector, then this will be used.\n * The `domElement` can also be a function with the {@link SnippetConfig} as parameter which\n * returns an Element or element selector to use.\n * If it is not present, a new <div> Element is created and appended to the body.\n *\n * @param domElement - {@link InstallXOptions.domElement | Element, string or function} Used\n * to mount the Vue Application.\n *\n * @returns The Element to use as mounting target for the Vue Application.\n * @internal\n */\n protected getMountingTarget(domElement?: InstallXOptions['domElement']): Element {\n if (isFunction(domElement)) {\n domElement = domElement(this.snippetConfig!);\n }\n if (typeof domElement === 'string') {\n const target = document.querySelector(domElement);\n if (!target) {\n throw Error(\n `XComponents app couldn't be mounted: Element \"${domElement}\" couldn't be found`\n );\n }\n return target;\n }\n return domElement ?? document.body.appendChild(document.createElement('div'));\n }\n\n /**\n * It updates all the provided properties from the current snippet config.\n *\n * @param newSnippetConfig - All the properties to be updated in the {@link SnippetConfig}.\n *\n * @internal\n */\n protected updateSnippetConfig(newSnippetConfig: Partial<SnippetConfig>): void {\n if (!this.snippetConfig) {\n return;\n }\n forEach(this.normaliseSnippetConfig(newSnippetConfig), (name, value) => {\n this.getVue().set(this.snippetConfig!, name, value);\n });\n }\n}\n"],"names":[],"mappings":";;;;;;AAiBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAuEa,UAAU;;;;;;;;;;;;;IAsBrB,YAAsC,OAAwB;QAAxB,YAAO,GAAP,OAAO,CAAiB;QAC5D,IAAI,CAAC,SAAS,EAAE,CAAC;KAClB;;;;;;;;IASS,SAAS;QACjB,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,OAAO,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CAAC,gBAAwC;QACpE,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE;YACvB,OAAO;SACR;QACD,OAAO,CAAC,IAAI,CAAC,sBAAsB,CAAC,gBAAgB,CAAC,EAAE,CAAC,IAAI,EAAE,KAAK;YACjE,IAAI,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,aAAc,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;SACrD,CAAC,CAAC;KACJ;;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@empathyco/x-components",
3
- "version": "3.0.0-alpha.221",
3
+ "version": "3.0.0-alpha.222",
4
4
  "description": "Empathy X Components",
5
5
  "author": "Empathy Systems Corporation S.L.",
6
6
  "license": "Apache-2.0",
@@ -135,5 +135,5 @@
135
135
  "access": "public",
136
136
  "directory": "dist"
137
137
  },
138
- "gitHead": "319245fcf4df5b0a1227bfe336527928f3159a46"
138
+ "gitHead": "3a41e63e2cc9611d146378335f892b5e85200435"
139
139
  }
@@ -23091,7 +23091,7 @@
23091
23091
  {
23092
23092
  "kind": "PropertySignature",
23093
23093
  "canonicalReference": "@empathyco/x-components!InstallXOptions#domElement:member",
23094
- "docComment": "/**\n * An Element | string to indicate the HTML element that will contain the Vue application. If string selector is passed and the element doesn't exits, the {@link XInstaller} will create it.\n */\n",
23094
+ "docComment": "/**\n * An Element | string | function to indicate the HTML element that will contain the Vue application. If it isn't passed, the {@link XInstaller} will create the target element.\n */\n",
23095
23095
  "excerptTokens": [
23096
23096
  {
23097
23097
  "kind": "Content",
@@ -23104,7 +23104,25 @@
23104
23104
  },
23105
23105
  {
23106
23106
  "kind": "Content",
23107
- "text": " | string"
23107
+ "text": " | string | ((snippetConfig: "
23108
+ },
23109
+ {
23110
+ "kind": "Reference",
23111
+ "text": "NormalisedSnippetConfig",
23112
+ "canonicalReference": "@empathyco/x-components!NormalisedSnippetConfig:type"
23113
+ },
23114
+ {
23115
+ "kind": "Content",
23116
+ "text": ") => "
23117
+ },
23118
+ {
23119
+ "kind": "Reference",
23120
+ "text": "Element",
23121
+ "canonicalReference": "!Element:interface"
23122
+ },
23123
+ {
23124
+ "kind": "Content",
23125
+ "text": " | string)"
23108
23126
  },
23109
23127
  {
23110
23128
  "kind": "Content",
@@ -23116,7 +23134,7 @@
23116
23134
  "name": "domElement",
23117
23135
  "propertyTypeTokenRange": {
23118
23136
  "startIndex": 1,
23119
- "endIndex": 3
23137
+ "endIndex": 7
23120
23138
  }
23121
23139
  },
23122
23140
  {
@@ -2252,7 +2252,7 @@ export interface InstallXOptions<API extends XAPI = XAPI> extends XPluginOptions
2252
2252
  api?: API | false;
2253
2253
  app?: VueConstructor | ComponentOptions<Vue>;
2254
2254
  bus?: XBus;
2255
- domElement?: Element | string;
2255
+ domElement?: Element | string | ((snippetConfig: NormalisedSnippetConfig) => Element | string);
2256
2256
  installExtraPlugins?(options: ExtraPluginsOptions): VueConstructorPartialArgument | Promise<VueConstructorPartialArgument>;
2257
2257
  onCreateApp?: (app: Vue) => void;
2258
2258
  plugin?: PluginObject<XPluginOptions>;
@@ -5345,7 +5345,7 @@ export class XInstaller {
5345
5345
  // @internal
5346
5346
  protected createBus(): XBus;
5347
5347
  // @internal
5348
- protected getMountingTarget(elementOrSelector?: string | Element): Element;
5348
+ protected getMountingTarget(domElement?: InstallXOptions['domElement']): Element;
5349
5349
  // @internal
5350
5350
  protected getPluginOptions(): XPluginOptions;
5351
5351
  // @internal
@@ -25,11 +25,10 @@ export interface InstallXOptions<API extends XAPI = XAPI> extends XPluginOptions
25
25
  */
26
26
  bus?: XBus;
27
27
  /**
28
- * An Element | string to indicate the HTML element that will contain the Vue
29
- * application. If string selector is passed and the element doesn't exits, the
30
- * {@link XInstaller} will create it.
28
+ * An Element | string | function to indicate the HTML element that will contain the Vue
29
+ * application. If it isn't passed, the {@link XInstaller} will create the target element.
31
30
  */
32
- domElement?: Element | string;
31
+ domElement?: Element | string | ((snippetConfig: NormalisedSnippetConfig) => Element | string);
33
32
  /**
34
33
  * The XPlugin which will be installed. If not passed, an instance of {@link XPlugin} will be
35
34
  * installed.
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/x-installer/x-installer/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,KAAK,CAAC;AACrE,OAAO,EAAE,IAAI,EAAE,MAAM,2BAA2B,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,uBAAuB,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAEjE;;;;;GAKG;AACH,MAAM,WAAW,eAAe,CAAC,GAAG,SAAS,IAAI,GAAG,IAAI,CAAE,SAAQ,cAAc;IAC9E;;;OAGG;IACH,GAAG,CAAC,EAAE,cAAc,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC;IAC7C;;;OAGG;IACH,GAAG,CAAC,EAAE,GAAG,GAAG,KAAK,CAAC;IAClB;;;OAGG;IACH,GAAG,CAAC,EAAE,IAAI,CAAC;IACX;;;;OAIG;IACH,UAAU,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IAC9B;;;OAGG;IACH,MAAM,CAAC,EAAE,YAAY,CAAC,cAAc,CAAC,CAAC;IACtC;;;;OAIG;IACH,GAAG,CAAC,EAAE,cAAc,CAAC;IACrB;;;;;;;;;;;;;OAaG;IACH,UAAU,CAAC,EAAE,6BAA6B,CAAC;IAE3C;;;;OAIG;IACH,WAAW,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,CAAC;IACjC;;;;;;;OAOG;IACH,mBAAmB,CAAC,CAClB,OAAO,EAAE,mBAAmB,GAC3B,6BAA6B,GAAG,OAAO,CAAC,6BAA6B,CAAC,CAAC;CAC3E;AAED;;;;GAIG;AACH,MAAM,WAAW,mBAAmB;IAClC,2CAA2C;IAC3C,GAAG,EAAE,cAAc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AAM,CAAC,EAAE,YAAY,CAAC,cAAc,CAAC,CAAC;IACtC;;;;OAIG;IACH,GAAG,CAAC,EAAE,cAAc,CAAC;IACrB;;;;;;;;;;;;;OAaG;IACH,UAAU,CAAC,EAAE,6BAA6B,CAAC;IAE3C;;;;OAIG;IACH,WAAW,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,CAAC;IACjC;;;;;;;OAOG;IACH,mBAAmB,CAAC,CAClB,OAAO,EAAE,mBAAmB,GAC3B,6BAA6B,GAAG,OAAO,CAAC,6BAA6B,CAAC,CAAC;CAC3E;AAED;;;;GAIG;AACH,MAAM,WAAW,mBAAmB;IAClC,2CAA2C;IAC3C,GAAG,EAAE,cAAc,CAAC;IACpB,sFAAsF;IACtF,GAAG,EAAE,IAAI,CAAC;IACV;;;OAGG;IACH,OAAO,EAAE,uBAAuB,CAAC;CAClC;AAED;;;;GAIG;AACH,oBAAY,6BAA6B,GAAG,OAAO,CAAC,qBAAqB,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAE9F;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC1B,gDAAgD;IAChD,GAAG,CAAC,EAAE,GAAG,CAAC;IACV,2CAA2C;IAC3C,GAAG,CAAC,EAAE,IAAI,CAAC;IACX,oDAAoD;IACpD,GAAG,EAAE,IAAI,CAAC;IACV,8CAA8C;IAC9C,MAAM,EAAE,YAAY,CAAC,cAAc,CAAC,CAAC;CACtC"}
@@ -197,16 +197,19 @@ export declare class XInstaller {
197
197
  protected normaliseSnippetConfig(snippetConfig: SnippetConfig): NormalisedSnippetConfig;
198
198
  protected normaliseSnippetConfig(snippetConfig: Partial<SnippetConfig>): Partial<SnippetConfig>;
199
199
  /**
200
- * It returns the HTML element to mount the Vue Application. If the `domElement` parameter in the
201
- * {@link InstallXOptions} is an Element or a string, then it is used. If it is
202
- * not present then a new <div> Element is created and append to the body to be used.
200
+ * It returns the HTML element to mount the Vue Application. If the `domElement` parameter in
201
+ * the {@link InstallXOptions} is an Element or an element selector, then this will be used.
202
+ * The `domElement` can also be a function with the {@link SnippetConfig} as parameter which
203
+ * returns an Element or element selector to use.
204
+ * If it is not present, a new <div> Element is created and appended to the body.
203
205
  *
204
- * @param elementOrSelector - String or Element used to mount the Vue App.
206
+ * @param domElement - {@link InstallXOptions.domElement | Element, string or function} Used
207
+ * to mount the Vue Application.
205
208
  *
206
- * @returns The Element to use as mounting point for the Vue App.
209
+ * @returns The Element to use as mounting target for the Vue Application.
207
210
  * @internal
208
211
  */
209
- protected getMountingTarget(elementOrSelector?: string | Element): Element;
212
+ protected getMountingTarget(domElement?: InstallXOptions['domElement']): Element;
210
213
  /**
211
214
  * It updates all the provided properties from the current snippet config.
212
215
  *
@@ -1 +1 @@
1
- {"version":3,"file":"x-installer.d.ts","sourceRoot":"","sources":["../../../../src/x-installer/x-installer/x-installer.ts"],"names":[],"mappings":"AACA,OAAO,GAAG,EAAE,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,KAAK,CAAC;AAExD,OAAO,EAAE,IAAI,EAAE,MAAM,2BAA2B,CAAC;AAEjD,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,uBAAuB,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAEhF,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,6BAA6B,EAAE,MAAM,SAAS,CAAC;AAEtF,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,UAAU,CAAC,EAAE,IAAI,CAAC;QAClB,KAAK,CAAC,EAAE,CAAC,MAAM,aAAa,CAAC,GAAG,aAAa,CAAC;KAC/C;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsEG;AACH,qBAAa,UAAU;IAsBF,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,eAAe;IArB9D,OAAO,C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