@digipair/skill-web-chatbot 0.4.10 → 0.4.11

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/index.cjs2.js CHANGED
@@ -55747,7 +55747,21 @@ const applyTemplate = (value, context)=>{
55747
55747
  const executePins = async (settingsOrigin, context = {}, options = {
55748
55748
  libraries: {}
55749
55749
  })=>{
55750
- const settings = await preparePinsSettings(settingsOrigin, context, options);
55750
+ var _settings_conditions;
55751
+ const settings = await preparePinsSettings(settingsOrigin, context);
55752
+ if ((_settings_conditions = settings.conditions) == null ? void 0 : _settings_conditions.each) {
55753
+ return Promise.all(settings.conditions.each.filter((item)=>typeof item.conditions.if === 'undefined' || item.conditions.if).map((item)=>executePins(_extends({}, settings, {
55754
+ conditions: _extends({}, settings.conditions, {
55755
+ each: undefined
55756
+ })
55757
+ }), _extends({}, context, {
55758
+ item,
55759
+ parent: {
55760
+ item: context.item,
55761
+ parent: context.parent
55762
+ }
55763
+ }), options)));
55764
+ }
55751
55765
  const version = options.libraries[settings.library] || 'latest';
55752
55766
  const library = _config$1.LIBRARIES[settings.library] || (typeof window === 'undefined' ? require(settings.library) : await (function (t) { return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(t)); }); })(`${_config$1.BASE_URL}/${settings.library}@${version}/index.esm.js`));
55753
55767
  const pins = library == null ? void 0 : library[settings.element];
@@ -55763,7 +55777,11 @@ const executePinsList = async (pinsSettingsList, context, options = {
55763
55777
  const steps = [];
55764
55778
  // parcourir tous les pins
55765
55779
  for(let i = 0; i < pinsSettingsList.length; i++){
55780
+ var _settings_conditions;
55766
55781
  const settings = pinsSettingsList[i];
55782
+ if (typeof ((_settings_conditions = settings.conditions) == null ? void 0 : _settings_conditions.if) !== 'undefined' && !settings.conditions.if) {
55783
+ continue;
55784
+ }
55767
55785
  previous = await executePins(settings, _extends({}, context, {
55768
55786
  previous,
55769
55787
  steps,
@@ -55780,9 +55798,31 @@ const executePinsList = async (pinsSettingsList, context, options = {
55780
55798
  }
55781
55799
  return previous;
55782
55800
  };
55783
- const generateElementFromPins = async (pinsSettings, context, options = {
55801
+ const generateElementFromPins = async (pinsSettings, parent, context, options = {
55784
55802
  libraries: {}
55785
55803
  })=>{
55804
+ var _settings_conditions, _settings_conditions1;
55805
+ const settings = await preparePinsSettings(pinsSettings, context);
55806
+ if ((_settings_conditions = settings.conditions) == null ? void 0 : _settings_conditions.each) {
55807
+ for(let i = 0; i < settings.conditions.each.length; i++){
55808
+ const item = settings.conditions.each[i];
55809
+ await generateElementFromPins(_extends({}, settings, {
55810
+ conditions: _extends({}, settings.conditions, {
55811
+ each: undefined
55812
+ })
55813
+ }), parent, _extends({}, context, {
55814
+ item,
55815
+ parent: {
55816
+ item: context.item,
55817
+ parent: context.parent
55818
+ }
55819
+ }), options);
55820
+ }
55821
+ return;
55822
+ }
55823
+ if (typeof ((_settings_conditions1 = settings.conditions) == null ? void 0 : _settings_conditions1.if) !== 'undefined' && !settings.conditions.if) {
55824
+ return;
55825
+ }
55786
55826
  const element = document.createElement(pinsSettings.element);
55787
55827
  element.setAttribute('data-digipair-pins', '');
55788
55828
  const library = pinsSettings.library;
@@ -55790,7 +55830,6 @@ const generateElementFromPins = async (pinsSettings, context, options = {
55790
55830
  const version = options.libraries[library] || 'latest';
55791
55831
  (function (t) { return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(t)); }); })(`${_config$1.BASE_URL}/${library}@${version}/index.esm.js`);
55792
55832
  }
55793
- const settings = await preparePinsSettings(pinsSettings, context, options);
55794
55833
  Object.entries(settings.properties || {}).forEach(([key, value])=>{
55795
55834
  if (key === 'textContent') {
55796
55835
  element.textContent = value;
@@ -55812,23 +55851,21 @@ const generateElementFromPins = async (pinsSettings, context, options = {
55812
55851
  const pinsList = settings.pins || [];
55813
55852
  for(let i = 0; i < pinsList.length; i++){
55814
55853
  const item = pinsList[i];
55815
- const child = await generateElementFromPins(item, settings.context, options);
55816
- element.appendChild(child);
55854
+ await generateElementFromPins(item, element, settings.context, options);
55817
55855
  }
55856
+ parent == null ? void 0 : parent.appendChild(element);
55818
55857
  return element;
55819
55858
  };
55820
- const preparePinsSettings = async (settings, context, options = {
55821
- libraries: {}
55822
- })=>{
55859
+ const preparePinsSettings = async (settings, context)=>{
55823
55860
  const localContext = _extends({}, context, {
55824
55861
  variables: context.variables || {},
55825
- requests: context.requests || {}
55862
+ conditions: context.conditions || {}
55826
55863
  });
55827
55864
  for (const [key, value] of Object.entries(settings.variables || {})){
55828
55865
  localContext.variables[key] = applyTemplate(value, localContext);
55829
55866
  }
55830
- for (const [key, value] of Object.entries(settings.requests || {})){
55831
- localContext.requests[key] = await executePins(value, localContext, options);
55867
+ for (const [key, value] of Object.entries(settings.conditions || {})){
55868
+ localContext.conditions[key] = await applyTemplate(value, localContext);
55832
55869
  }
55833
55870
  const properties = {};
55834
55871
  for (const [key, value] of Object.entries(settings.properties || {})){
@@ -55849,7 +55886,7 @@ class InputsElement extends s$3 {
55849
55886
  }
55850
55887
  render() {
55851
55888
  return x`
55852
- ${(this.inputs || []).map((pins)=>x`${m(generateElementFromPins(pins, this.context).then((el)=>{
55889
+ ${(this.inputs || []).map((pins)=>x`${m(generateElementFromPins(pins, null, this.context).then((el)=>{
55853
55890
  setTimeout(()=>this.dispatchEvent(new CustomEvent('change')), 1);
55854
55891
  el.addEventListener('change', ()=>this.dispatchEvent(new CustomEvent('change')));
55855
55892
  return el;
package/index.esm2.js CHANGED
@@ -55727,7 +55727,21 @@ const applyTemplate = (value, context)=>{
55727
55727
  const executePins = async (settingsOrigin, context = {}, options = {
55728
55728
  libraries: {}
55729
55729
  })=>{
55730
- const settings = await preparePinsSettings(settingsOrigin, context, options);
55730
+ var _settings_conditions;
55731
+ const settings = await preparePinsSettings(settingsOrigin, context);
55732
+ if ((_settings_conditions = settings.conditions) == null ? void 0 : _settings_conditions.each) {
55733
+ return Promise.all(settings.conditions.each.filter((item)=>typeof item.conditions.if === 'undefined' || item.conditions.if).map((item)=>executePins(_extends({}, settings, {
55734
+ conditions: _extends({}, settings.conditions, {
55735
+ each: undefined
55736
+ })
55737
+ }), _extends({}, context, {
55738
+ item,
55739
+ parent: {
55740
+ item: context.item,
55741
+ parent: context.parent
55742
+ }
55743
+ }), options)));
55744
+ }
55731
55745
  const version = options.libraries[settings.library] || 'latest';
55732
55746
  const library = _config$1.LIBRARIES[settings.library] || (typeof window === 'undefined' ? require(settings.library) : await import(`${_config$1.BASE_URL}/${settings.library}@${version}/index.esm.js`));
55733
55747
  const pins = library == null ? void 0 : library[settings.element];
@@ -55743,7 +55757,11 @@ const executePinsList = async (pinsSettingsList, context, options = {
55743
55757
  const steps = [];
55744
55758
  // parcourir tous les pins
55745
55759
  for(let i = 0; i < pinsSettingsList.length; i++){
55760
+ var _settings_conditions;
55746
55761
  const settings = pinsSettingsList[i];
55762
+ if (typeof ((_settings_conditions = settings.conditions) == null ? void 0 : _settings_conditions.if) !== 'undefined' && !settings.conditions.if) {
55763
+ continue;
55764
+ }
55747
55765
  previous = await executePins(settings, _extends({}, context, {
55748
55766
  previous,
55749
55767
  steps,
@@ -55760,9 +55778,31 @@ const executePinsList = async (pinsSettingsList, context, options = {
55760
55778
  }
55761
55779
  return previous;
55762
55780
  };
55763
- const generateElementFromPins = async (pinsSettings, context, options = {
55781
+ const generateElementFromPins = async (pinsSettings, parent, context, options = {
55764
55782
  libraries: {}
55765
55783
  })=>{
55784
+ var _settings_conditions, _settings_conditions1;
55785
+ const settings = await preparePinsSettings(pinsSettings, context);
55786
+ if ((_settings_conditions = settings.conditions) == null ? void 0 : _settings_conditions.each) {
55787
+ for(let i = 0; i < settings.conditions.each.length; i++){
55788
+ const item = settings.conditions.each[i];
55789
+ await generateElementFromPins(_extends({}, settings, {
55790
+ conditions: _extends({}, settings.conditions, {
55791
+ each: undefined
55792
+ })
55793
+ }), parent, _extends({}, context, {
55794
+ item,
55795
+ parent: {
55796
+ item: context.item,
55797
+ parent: context.parent
55798
+ }
55799
+ }), options);
55800
+ }
55801
+ return;
55802
+ }
55803
+ if (typeof ((_settings_conditions1 = settings.conditions) == null ? void 0 : _settings_conditions1.if) !== 'undefined' && !settings.conditions.if) {
55804
+ return;
55805
+ }
55766
55806
  const element = document.createElement(pinsSettings.element);
55767
55807
  element.setAttribute('data-digipair-pins', '');
55768
55808
  const library = pinsSettings.library;
@@ -55770,7 +55810,6 @@ const generateElementFromPins = async (pinsSettings, context, options = {
55770
55810
  const version = options.libraries[library] || 'latest';
55771
55811
  import(`${_config$1.BASE_URL}/${library}@${version}/index.esm.js`);
55772
55812
  }
55773
- const settings = await preparePinsSettings(pinsSettings, context, options);
55774
55813
  Object.entries(settings.properties || {}).forEach(([key, value])=>{
55775
55814
  if (key === 'textContent') {
55776
55815
  element.textContent = value;
@@ -55792,23 +55831,21 @@ const generateElementFromPins = async (pinsSettings, context, options = {
55792
55831
  const pinsList = settings.pins || [];
55793
55832
  for(let i = 0; i < pinsList.length; i++){
55794
55833
  const item = pinsList[i];
55795
- const child = await generateElementFromPins(item, settings.context, options);
55796
- element.appendChild(child);
55834
+ await generateElementFromPins(item, element, settings.context, options);
55797
55835
  }
55836
+ parent == null ? void 0 : parent.appendChild(element);
55798
55837
  return element;
55799
55838
  };
55800
- const preparePinsSettings = async (settings, context, options = {
55801
- libraries: {}
55802
- })=>{
55839
+ const preparePinsSettings = async (settings, context)=>{
55803
55840
  const localContext = _extends({}, context, {
55804
55841
  variables: context.variables || {},
55805
- requests: context.requests || {}
55842
+ conditions: context.conditions || {}
55806
55843
  });
55807
55844
  for (const [key, value] of Object.entries(settings.variables || {})){
55808
55845
  localContext.variables[key] = applyTemplate(value, localContext);
55809
55846
  }
55810
- for (const [key, value] of Object.entries(settings.requests || {})){
55811
- localContext.requests[key] = await executePins(value, localContext, options);
55847
+ for (const [key, value] of Object.entries(settings.conditions || {})){
55848
+ localContext.conditions[key] = await applyTemplate(value, localContext);
55812
55849
  }
55813
55850
  const properties = {};
55814
55851
  for (const [key, value] of Object.entries(settings.properties || {})){
@@ -55829,7 +55866,7 @@ class InputsElement extends s$3 {
55829
55866
  }
55830
55867
  render() {
55831
55868
  return x`
55832
- ${(this.inputs || []).map((pins)=>x`${m(generateElementFromPins(pins, this.context).then((el)=>{
55869
+ ${(this.inputs || []).map((pins)=>x`${m(generateElementFromPins(pins, null, this.context).then((el)=>{
55833
55870
  setTimeout(()=>this.dispatchEvent(new CustomEvent('change')), 1);
55834
55871
  el.addEventListener('change', ()=>this.dispatchEvent(new CustomEvent('change')));
55835
55872
  return el;
@@ -14,14 +14,10 @@ export declare const executePinsList: (pinsSettingsList: PinsSettings[], context
14
14
  [key: string]: string;
15
15
  };
16
16
  }) => Promise<any>;
17
- export declare const generateElementFromPins: (pinsSettings: PinsSettings, context: any, options?: {
17
+ export declare const generateElementFromPins: (pinsSettings: PinsSettings, parent: Element, context: any, options?: {
18
18
  libraries: {
19
19
  [key: string]: string;
20
20
  };
21
- }) => Promise<Element>;
22
- export declare const preparePinsSettings: (settings: PinsSettings, context: any, options?: {
23
- libraries: {
24
- [key: string]: string;
25
- };
26
- }) => Promise<PinsSettings>;
21
+ }) => Promise<Element | void>;
22
+ export declare const preparePinsSettings: (settings: PinsSettings, context: any) => Promise<PinsSettings>;
27
23
  export {};
@@ -9,8 +9,9 @@ export interface PinsSettings {
9
9
  variables?: {
10
10
  [key: string]: any;
11
11
  };
12
- requests?: {
13
- [key: string]: PinsSettings;
12
+ conditions?: {
13
+ if?: boolean;
14
+ each?: any[];
14
15
  };
15
16
  pins?: PinsSettings[];
16
17
  events?: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digipair/skill-web-chatbot",
3
- "version": "0.4.10",
3
+ "version": "0.4.11",
4
4
  "dependencies": {},
5
5
  "typings": "./index.d.ts",
6
6
  "main": "./index.cjs.js",