@micro-lc/preview 0.4.2 → 0.5.0-rc1

Sign up to get free protection for your applications and to get access to all the features.
@@ -3266,6 +3266,13 @@ var observable = function() {
3266
3266
  function identity(x2) {
3267
3267
  return x2;
3268
3268
  }
3269
+ function pipe() {
3270
+ var fns = [];
3271
+ for (var _i = 0; _i < arguments.length; _i++) {
3272
+ fns[_i] = arguments[_i];
3273
+ }
3274
+ return pipeFromArray(fns);
3275
+ }
3269
3276
  function pipeFromArray(fns) {
3270
3277
  if (fns.length === 0) {
3271
3278
  return identity;
@@ -3869,6 +3876,9 @@ function isScheduler(value) {
3869
3876
  function last(arr) {
3870
3877
  return arr[arr.length - 1];
3871
3878
  }
3879
+ function popResultSelector(args) {
3880
+ return isFunction(last(args)) ? args.pop() : void 0;
3881
+ }
3872
3882
  function popScheduler(args) {
3873
3883
  return isScheduler(last(args)) ? args.pop() : void 0;
3874
3884
  }
@@ -4276,6 +4286,58 @@ function map(project, thisArg) {
4276
4286
  }));
4277
4287
  });
4278
4288
  }
4289
+ var isArray$1 = Array.isArray;
4290
+ function callOrApply(fn, args) {
4291
+ return isArray$1(args) ? fn.apply(void 0, __spreadArray([], __read(args))) : fn(args);
4292
+ }
4293
+ function mapOneOrManyArgs(fn) {
4294
+ return map(function(args) {
4295
+ return callOrApply(fn, args);
4296
+ });
4297
+ }
4298
+ function combineLatestInit(observables, scheduler, valueTransform) {
4299
+ if (valueTransform === void 0) {
4300
+ valueTransform = identity;
4301
+ }
4302
+ return function(subscriber) {
4303
+ maybeSchedule(scheduler, function() {
4304
+ var length = observables.length;
4305
+ var values = new Array(length);
4306
+ var active = length;
4307
+ var remainingFirstValues = length;
4308
+ var _loop_1 = function(i3) {
4309
+ maybeSchedule(scheduler, function() {
4310
+ var source = from(observables[i3], scheduler);
4311
+ var hasFirstValue = false;
4312
+ source.subscribe(createOperatorSubscriber(subscriber, function(value) {
4313
+ values[i3] = value;
4314
+ if (!hasFirstValue) {
4315
+ hasFirstValue = true;
4316
+ remainingFirstValues--;
4317
+ }
4318
+ if (!remainingFirstValues) {
4319
+ subscriber.next(valueTransform(values.slice()));
4320
+ }
4321
+ }, function() {
4322
+ if (!--active) {
4323
+ subscriber.complete();
4324
+ }
4325
+ }));
4326
+ }, subscriber);
4327
+ };
4328
+ for (var i2 = 0; i2 < length; i2++) {
4329
+ _loop_1(i2);
4330
+ }
4331
+ }, subscriber);
4332
+ };
4333
+ }
4334
+ function maybeSchedule(scheduler, execute, subscription) {
4335
+ if (scheduler) {
4336
+ executeSchedule(subscription, scheduler, execute);
4337
+ } else {
4338
+ execute();
4339
+ }
4340
+ }
4279
4341
  function mergeInternals(source, subscriber, project, concurrent, onBeforeNext, expand, innerSubScheduler, additionalFinalizer) {
4280
4342
  var buffer = [];
4281
4343
  var active = 0;
@@ -4384,6 +4446,22 @@ function timer(dueTime, intervalOrScheduler, scheduler) {
4384
4446
  }, due);
4385
4447
  });
4386
4448
  }
4449
+ function interval(period, scheduler) {
4450
+ if (period === void 0) {
4451
+ period = 0;
4452
+ }
4453
+ if (scheduler === void 0) {
4454
+ scheduler = asyncScheduler;
4455
+ }
4456
+ if (period < 0) {
4457
+ period = 0;
4458
+ }
4459
+ return timer(period, period, scheduler);
4460
+ }
4461
+ var isArray = Array.isArray;
4462
+ function argsOrArgArray(args) {
4463
+ return args.length === 1 && isArray(args[0]) ? args[0] : args;
4464
+ }
4387
4465
  function filter(predicate, thisArg) {
4388
4466
  return operate(function(source, subscriber) {
4389
4467
  var index = 0;
@@ -4466,6 +4544,23 @@ function bufferTime(bufferTimeSpan) {
4466
4544
  source.subscribe(bufferTimeSubscriber);
4467
4545
  });
4468
4546
  }
4547
+ function combineLatest() {
4548
+ var args = [];
4549
+ for (var _i = 0; _i < arguments.length; _i++) {
4550
+ args[_i] = arguments[_i];
4551
+ }
4552
+ var resultSelector = popResultSelector(args);
4553
+ return resultSelector ? pipe(combineLatest.apply(void 0, __spreadArray([], __read(args))), mapOneOrManyArgs(resultSelector)) : operate(function(source, subscriber) {
4554
+ combineLatestInit(__spreadArray([source], __read(argsOrArgArray(args))))(subscriber);
4555
+ });
4556
+ }
4557
+ function combineLatestWith() {
4558
+ var otherSources = [];
4559
+ for (var _i = 0; _i < arguments.length; _i++) {
4560
+ otherSources[_i] = arguments[_i];
4561
+ }
4562
+ return combineLatest.apply(void 0, __spreadArray([], __read(otherSources)));
4563
+ }
4469
4564
  function concatMap(project, resultSelector) {
4470
4565
  return isFunction(resultSelector) ? mergeMap(project, resultSelector, 1) : mergeMap(project, 1);
4471
4566
  }
@@ -4525,145 +4620,27 @@ function tap(observerOrNext, error2, complete) {
4525
4620
  }));
4526
4621
  }) : identity;
4527
4622
  }
4528
- const DEFAULT_LANGUAGE = "en";
4529
- const localizeText = (input, lang = DEFAULT_LANGUAGE) => {
4530
- if (typeof input === "string") {
4531
- return input;
4532
- }
4533
- return input == null ? void 0 : input[lang];
4534
- };
4535
- function translateObject(obj) {
4536
- return Object.entries(obj).reduce((out, [key, value]) => {
4537
- out[key] = localizeText(value);
4538
- return out;
4539
- }, {});
4540
- }
4541
- const noop = (..._args) => {
4542
- };
4543
- const toArray$1 = (input) => Array.isArray(input) ? input : [input];
4544
- const urlMakerFactory = ({ document: { baseURI }, location: { href } }) => (input) => new URL(input, new URL(baseURI, href));
4545
- const toURL = (urlMaker, info) => {
4546
- let url = info;
4547
- if (!(info instanceof URL)) {
4548
- url = urlMaker(typeof info === "string" ? info : info.url);
4549
- }
4550
- return url;
4551
- };
4552
- const trimLocationOrigin = (origin, url) => {
4553
- const { href, origin: linkOrigin } = url;
4554
- if (origin === linkOrigin) {
4555
- return href.substring(origin.length);
4556
- }
4557
- return href;
4558
- };
4559
- const getElement = (document2, context, nth = 0) => {
4560
- const { selectors } = context;
4561
- return document2.querySelector(selectors[nth]);
4562
- };
4563
- function getElementBySelector(selector) {
4564
- return document.querySelector(selector);
4565
- }
4566
- const unfocus = (element, mapping) => {
4567
- const originalStyle = mapping.get(element);
4568
- if (originalStyle) {
4569
- const { css, rest, subscription } = originalStyle;
4570
- rest.forEach((el) => {
4571
- var _a2;
4572
- return (_a2 = el.__unfocus_handler) == null ? void 0 : _a2.call(el);
4573
- });
4574
- subscription.unsubscribe();
4575
- originalStyle.elementToFocus.forEach((el, idx) => {
4576
- Object.assign(el.style, css[idx]);
4577
- });
4578
- }
4579
- mapping.delete(element);
4580
- };
4581
- const noUndefined = (input) => input !== void 0;
4582
- function focus(document2, obs$, mode$) {
4583
- const stylesMap = /* @__PURE__ */ new Map();
4584
- const getBySelector = getElementBySelector.bind(document2);
4585
- const subscription = obs$.pipe(
4586
- pairwise(),
4587
- tap(([current]) => {
4588
- var _a2;
4589
- if (current !== void 0) {
4590
- const prev = getElement(document2, current);
4591
- if (prev !== null) {
4592
- (_a2 = prev.__unfocus_handler) == null ? void 0 : _a2.call(prev);
4593
- unfocus(prev, stylesMap);
4594
- }
4595
- }
4596
- }),
4597
- map(([, next]) => next),
4598
- filter(noUndefined),
4599
- map((next) => {
4600
- const [first, ...rest] = next.selectors;
4601
- const otherElements = rest.reduce((arr, selector) => {
4602
- var _a2;
4603
- const el = getBySelector(selector);
4604
- if (el) {
4605
- arr.push(el);
4606
- const result = (_a2 = el.__focus_handler) == null ? void 0 : _a2.call(el);
4607
- if (result && "then" in result) {
4608
- result.catch(noop);
4609
- }
4610
- }
4611
- return arr;
4612
- }, []);
4613
- return { first, next, otherElements };
4614
- }),
4615
- map((next) => ({ ...next, firstElement: getBySelector(next.first) })),
4616
- filter((next) => next.firstElement !== null),
4617
- map((next) => {
4618
- var _a2, _b;
4619
- return { ...next, focus: (_b = (_a2 = next.firstElement).__focus_handler) == null ? void 0 : _b.call(_a2) };
4620
- }),
4621
- concatMap(({ focus: focusPromise, ...rest }) => {
4622
- const promise = focusPromise && "then" in focusPromise ? focusPromise : Promise.resolve(focusPromise != null ? focusPromise : rest.firstElement);
4623
- return promise.then((focusElement) => ({ focus: focusElement, ...rest })).catch(() => ({ focus: void 0, ...rest }));
4624
- })
4625
- ).subscribe(({ otherElements, next, firstElement, focus: focusContext }) => {
4626
- const cssKeys = Object.keys(next.style);
4627
- const stylePendingChanges = new Subscription();
4628
- const elementToFocus = toArray$1(focusContext != null ? focusContext : firstElement).filter(Boolean);
4629
- const initialStyles = { css: [], elementToFocus, rest: otherElements, subscription: stylePendingChanges };
4630
- const styles = cssKeys.reduce((acc, key) => {
4631
- elementToFocus.forEach((el, idx) => {
4632
- var _a2;
4633
- acc.css[idx] = Object.assign((_a2 = acc.css[idx]) != null ? _a2 : {}, { [key]: el.style[key] });
4634
- });
4635
- return acc;
4636
- }, initialStyles);
4637
- stylePendingChanges.add(mode$.pipe(filter((val) => val === "select"), take(1)).subscribe(() => {
4638
- elementToFocus.forEach((el) => {
4639
- Object.assign(el.style, next.style);
4640
- });
4641
- }));
4642
- stylesMap.set(firstElement, styles);
4643
- });
4644
- return () => subscription.unsubscribe();
4645
- }
4646
- var __defProp$4 = Object.defineProperty;
4647
- var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4648
- var __publicField$4 = (obj, key, value) => {
4649
- __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
4623
+ var __defProp$5 = Object.defineProperty;
4624
+ var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4625
+ var __publicField$5 = (obj, key, value) => {
4626
+ __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
4650
4627
  return value;
4651
4628
  };
4652
4629
  let Lexer$1 = class Lexer {
4653
4630
  constructor(input) {
4654
- __publicField$4(this, "_input");
4655
- __publicField$4(this, "_length");
4656
- __publicField$4(this, "_idx", 0);
4657
- __publicField$4(
4631
+ __publicField$5(this, "_input");
4632
+ __publicField$5(this, "_length");
4633
+ __publicField$5(this, "_idx", 0);
4634
+ __publicField$5(
4658
4635
  this,
4659
4636
  "_mode",
4660
4637
  0
4661
4638
  /* Literal */
4662
4639
  );
4663
- __publicField$4(this, "_literals", []);
4664
- __publicField$4(this, "_variables", []);
4665
- __publicField$4(this, "_braketCount", 0);
4666
- __publicField$4(this, "_done", false);
4640
+ __publicField$5(this, "_literals", []);
4641
+ __publicField$5(this, "_variables", []);
4642
+ __publicField$5(this, "_braketCount", 0);
4643
+ __publicField$5(this, "_done", false);
4667
4644
  this._input = input;
4668
4645
  this._length = input.length;
4669
4646
  }
@@ -4764,28 +4741,30 @@ function parse(input, context, preserveUnknown = false) {
4764
4741
  return acc;
4765
4742
  }
4766
4743
  const compileObject = (obj, context) => Object.fromEntries(Object.entries(obj).map(([key, value]) => [key, parse(value, context)]));
4767
- var __defProp$3 = Object.defineProperty;
4768
- var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4769
- var __publicField$3 = (obj, key, value) => {
4770
- __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
4744
+ var __defProp$4 = Object.defineProperty;
4745
+ var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4746
+ var __publicField$4 = (obj, key, value) => {
4747
+ __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
4771
4748
  return value;
4772
4749
  };
4773
4750
  const MIA_PREVIEW_ID = "__mia_preview_id";
4774
4751
  const OVERLAY_Z_INDEX = 1e6;
4775
4752
  const keys = {
4776
- "click-element": 0,
4777
- "ctrl-space": 0,
4753
+ "click-element": 1,
4754
+ "ctrl-space": 1,
4778
4755
  "focus-element": 0,
4779
- mousedown: 0,
4756
+ mousedown: 1,
4780
4757
  mousemove: 1,
4781
4758
  "new-configuration": 0,
4782
- notification: 0,
4783
- options: 0,
4784
- "request-resource": 0,
4785
- "tag-info": 0,
4786
- update: 0,
4787
- updated: 0
4788
- /* Default */
4759
+ notification: 1,
4760
+ options: 1,
4761
+ "request-resource": 1,
4762
+ "service-worker": 1,
4763
+ "set-source-map": 0,
4764
+ "tag-info": 1,
4765
+ update: 1,
4766
+ updated: 1
4767
+ /* Skip */
4789
4768
  };
4790
4769
  const isValidKey = (type) => Object.keys(keys).includes(type);
4791
4770
  function isInstanceMessage(input, signature) {
@@ -4825,10 +4804,10 @@ const generateDarkColorHex = () => {
4825
4804
  };
4826
4805
  class PostChannel {
4827
4806
  constructor(handler2) {
4828
- __publicField$3(this, "__instance");
4829
- __publicField$3(this, "__handler");
4830
- __publicField$3(this, "__window");
4831
- __publicField$3(this, "__randomColor");
4807
+ __publicField$4(this, "__instance");
4808
+ __publicField$4(this, "__handler");
4809
+ __publicField$4(this, "__window");
4810
+ __publicField$4(this, "__randomColor");
4832
4811
  this.__instance = "";
4833
4812
  this.__handler = handler2;
4834
4813
  this.__window = window;
@@ -4845,6 +4824,7 @@ class PostChannel {
4845
4824
  const hasTop = this.__window.top !== this.__window;
4846
4825
  console.groupCollapsed(`%c Msg from ${this.__window.origin} ${hasTop ? "(inner)" : "(top)"} `, Object.entries(style).map(([key, val]) => `${key}: ${val}`).join("; "));
4847
4826
  console.info(`window '${this.__window.origin}' is sending a message of type %c ${message.type} `, "background: lightgreen; color: darkgreen");
4827
+ console.log("to", to.document);
4848
4828
  console.log(message.content);
4849
4829
  console.groupEnd();
4850
4830
  }
@@ -4863,16 +4843,260 @@ class PostChannel {
4863
4843
  this.__window !== to && this.postMessage(to, message, origin);
4864
4844
  }
4865
4845
  recv(window2, from2 = null) {
4866
- const listener2 = ({ data, source }) => {
4846
+ const listener = ({ data, source }) => {
4867
4847
  if ((from2 === null || source === from2) && isInstanceMessage(data, this.__instance)) {
4868
4848
  const message = unsign(this.__instance, data);
4869
4849
  this.__handler(message);
4870
4850
  }
4871
4851
  };
4872
- window2.addEventListener("message", listener2);
4873
- return () => window2.removeEventListener("message", listener2);
4852
+ window2.addEventListener("message", listener);
4853
+ return () => window2.removeEventListener("message", listener);
4874
4854
  }
4875
4855
  }
4856
+ var __defProp$3 = Object.defineProperty;
4857
+ var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4858
+ var __publicField$3 = (obj, key, value) => {
4859
+ __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
4860
+ return value;
4861
+ };
4862
+ function registerChannels() {
4863
+ return {
4864
+ configuration: new ReplaySubject(),
4865
+ focus: new BehaviorSubject(void 0),
4866
+ infos: new ReplaySubject(),
4867
+ mocks: new ReplaySubject(),
4868
+ mode: new BehaviorSubject("select"),
4869
+ notification: new ReplaySubject(),
4870
+ setSourceMap: new ReplaySubject(),
4871
+ swReady: new ReplaySubject(1),
4872
+ updated: new Subject(),
4873
+ uppercaseTags: /* @__PURE__ */ new Set()
4874
+ };
4875
+ }
4876
+ const nextMode = (mode) => {
4877
+ let next = 0;
4878
+ const currentValue = mode.getValue();
4879
+ if (currentValue === "interact") {
4880
+ next = "select";
4881
+ } else if (currentValue === "select") {
4882
+ next = "interact";
4883
+ }
4884
+ mode.next(next);
4885
+ return next;
4886
+ };
4887
+ const subjects = registerChannels();
4888
+ function parentListener(message) {
4889
+ switch (message.type) {
4890
+ case "options": {
4891
+ const { content: { disableOverlay, redirectTo, timeout } } = message;
4892
+ if (disableOverlay) {
4893
+ Object.defineProperty(this.window, "__BACKOFFICE_CONFIGURATOR_DISABLE_OVERLAY__", { value: true });
4894
+ subjects.mode.next("interact");
4895
+ }
4896
+ if (timeout !== void 0) {
4897
+ Object.defineProperty(this.window, "__BACKOFFICE_CONFIGURATOR_PREVIEW_TIMEOUT__", { value: timeout });
4898
+ }
4899
+ const { window: { history } } = this;
4900
+ this.window.navigator.serviceWorker.ready.then(() => redirectTo && history.pushState(history.state, "", redirectTo)).catch(() => {
4901
+ });
4902
+ break;
4903
+ }
4904
+ case "ctrl-space":
4905
+ nextMode(subjects.mode);
4906
+ break;
4907
+ case "new-configuration":
4908
+ subjects.configuration.next({ ...message.content, type: "reset" });
4909
+ break;
4910
+ case "update":
4911
+ subjects.configuration.next({ ...message.content, type: "update" });
4912
+ break;
4913
+ case "focus-element":
4914
+ subjects.focus.next(message.content);
4915
+ break;
4916
+ case "set-source-map": {
4917
+ const { content: { dictionary } } = message;
4918
+ subjects.setSourceMap.next({
4919
+ ...message.content,
4920
+ dictionary: Object.entries(dictionary).reduce((acc, [from2, to]) => {
4921
+ try {
4922
+ const { href: fromUrl } = new URL(from2, this.window.location.href);
4923
+ const obj = typeof to === "string" ? { headers: {}, query: {}, to } : to;
4924
+ acc[fromUrl] = {
4925
+ originalFrom: from2,
4926
+ ...obj
4927
+ };
4928
+ } catch (e2) {
4929
+ }
4930
+ return acc;
4931
+ }, {})
4932
+ });
4933
+ break;
4934
+ }
4935
+ }
4936
+ }
4937
+ class ServiceWorkerChannel {
4938
+ constructor(handler2) {
4939
+ __publicField$3(this, "__handler");
4940
+ __publicField$3(this, "__window");
4941
+ __publicField$3(this, "__randomColor");
4942
+ this.__handler = handler2;
4943
+ this.__window = window;
4944
+ this.__randomColor = generateDarkColorHex();
4945
+ }
4946
+ send(to, message) {
4947
+ {
4948
+ const color = this.__randomColor;
4949
+ const background = `${color}22`;
4950
+ const style = { background, color };
4951
+ console.groupCollapsed(`%c Msg to Service Worker `, Object.entries(style).map(([key, val]) => `${key}: ${val}`).join("; "));
4952
+ console.info(`window '${this.__window.origin}' is sending a message of type %c ${message.type} `, "background: lightgreen; color: darkgreen");
4953
+ console.log(message.content);
4954
+ console.groupEnd();
4955
+ }
4956
+ to.postMessage(message);
4957
+ }
4958
+ get window() {
4959
+ return this.__window;
4960
+ }
4961
+ set window(win) {
4962
+ this.__window = win;
4963
+ }
4964
+ recv() {
4965
+ const swListener2 = ({ data }) => {
4966
+ this.__handler(data);
4967
+ };
4968
+ const { __window: { navigator: navigator2 } } = this;
4969
+ navigator2.serviceWorker.addEventListener("message", swListener2);
4970
+ return () => navigator2.serviceWorker.removeEventListener("message", swListener2);
4971
+ }
4972
+ }
4973
+ const swListener = (message) => {
4974
+ switch (message.type) {
4975
+ case "source-map-ack":
4976
+ subjects.swReady.next(0);
4977
+ break;
4978
+ }
4979
+ };
4980
+ const postChannel = new PostChannel(parentListener);
4981
+ const serviceWorkerChannel = new ServiceWorkerChannel(swListener);
4982
+ const DEFAULT_LANGUAGE = "en";
4983
+ const localizeText = (input, lang = DEFAULT_LANGUAGE) => {
4984
+ if (typeof input === "string") {
4985
+ return input;
4986
+ }
4987
+ return input == null ? void 0 : input[lang];
4988
+ };
4989
+ function translateObject(obj) {
4990
+ return Object.entries(obj).reduce((out, [key, value]) => {
4991
+ out[key] = localizeText(value);
4992
+ return out;
4993
+ }, {});
4994
+ }
4995
+ const noop = (..._args) => {
4996
+ };
4997
+ const toArray$1 = (input) => Array.isArray(input) ? input : [input];
4998
+ const urlMakerFactory = ({ document: { baseURI }, location: { href } }) => (input) => new URL(input, new URL(baseURI, href));
4999
+ const toURL = (urlMaker, info) => {
5000
+ let url = info;
5001
+ if (!(info instanceof URL)) {
5002
+ url = urlMaker(typeof info === "string" ? info : info.url);
5003
+ }
5004
+ return url;
5005
+ };
5006
+ const trimLocationOrigin = (origin, url) => {
5007
+ const { href, origin: linkOrigin } = url;
5008
+ if (origin === linkOrigin) {
5009
+ return href.substring(origin.length);
5010
+ }
5011
+ return href;
5012
+ };
5013
+ const getElement = (document2, context, nth = 0) => {
5014
+ const { selectors } = context;
5015
+ return document2.querySelector(selectors[nth]);
5016
+ };
5017
+ function getElementBySelector(selector) {
5018
+ return document.querySelector(selector);
5019
+ }
5020
+ const unfocus = (element, mapping) => {
5021
+ const originalStyle = mapping.get(element.getAttribute("__mia_preview_id"));
5022
+ if (originalStyle) {
5023
+ const { css, rest, subscription } = originalStyle;
5024
+ rest.forEach((el) => {
5025
+ var _a2;
5026
+ return (_a2 = el.__unfocus_handler) == null ? void 0 : _a2.call(el);
5027
+ });
5028
+ subscription.unsubscribe();
5029
+ originalStyle.elementToFocus.forEach((el, idx) => {
5030
+ Object.assign(el.style, css[idx]);
5031
+ });
5032
+ }
5033
+ mapping.delete(element.getAttribute("__mia_preview_id"));
5034
+ };
5035
+ const noUndefined = (input) => input !== void 0;
5036
+ function focus(document2, obs$, mode$) {
5037
+ const stylesMap = /* @__PURE__ */ new Map();
5038
+ const getBySelector = getElementBySelector.bind(document2);
5039
+ const subscription = obs$.pipe(
5040
+ pairwise(),
5041
+ tap(([current]) => {
5042
+ var _a2;
5043
+ if (current !== void 0) {
5044
+ const prev = getElement(document2, current);
5045
+ if (prev !== null) {
5046
+ (_a2 = prev.__unfocus_handler) == null ? void 0 : _a2.call(prev);
5047
+ unfocus(prev, stylesMap);
5048
+ }
5049
+ }
5050
+ }),
5051
+ map(([, next]) => next),
5052
+ filter(noUndefined),
5053
+ map((next) => {
5054
+ const [first, ...rest] = next.selectors;
5055
+ const otherElements = rest.reduce((arr, selector) => {
5056
+ var _a2;
5057
+ const el = getBySelector(selector);
5058
+ if (el) {
5059
+ arr.push(el);
5060
+ const result = (_a2 = el.__focus_handler) == null ? void 0 : _a2.call(el);
5061
+ if (result && "then" in result) {
5062
+ result.catch(noop);
5063
+ }
5064
+ }
5065
+ return arr;
5066
+ }, []);
5067
+ return { first, next, otherElements };
5068
+ }),
5069
+ map((next) => ({ ...next, firstElement: getBySelector(next.first) })),
5070
+ filter((next) => next.firstElement !== null),
5071
+ map((next) => {
5072
+ var _a2, _b;
5073
+ return { ...next, focus: (_b = (_a2 = next.firstElement).__focus_handler) == null ? void 0 : _b.call(_a2) };
5074
+ }),
5075
+ concatMap(({ focus: focusPromise, ...rest }) => {
5076
+ const promise = focusPromise && "then" in focusPromise ? focusPromise : Promise.resolve(focusPromise != null ? focusPromise : rest.firstElement);
5077
+ return promise.then((focusElement) => ({ focus: focusElement, ...rest })).catch(() => ({ focus: void 0, ...rest }));
5078
+ })
5079
+ ).subscribe(({ otherElements, next, firstElement, focus: focusContext }) => {
5080
+ const cssKeys = Object.keys(next.style);
5081
+ const stylePendingChanges = new Subscription();
5082
+ const elementToFocus = toArray$1(focusContext != null ? focusContext : firstElement).filter(Boolean);
5083
+ const initialStyles = { css: [], elementToFocus, rest: otherElements, subscription: stylePendingChanges };
5084
+ const styles = cssKeys.reduce((acc, key) => {
5085
+ elementToFocus.forEach((el, idx) => {
5086
+ var _a2;
5087
+ acc.css[idx] = Object.assign((_a2 = acc.css[idx]) != null ? _a2 : {}, { [key]: el.style[key] });
5088
+ });
5089
+ return acc;
5090
+ }, initialStyles);
5091
+ stylePendingChanges.add(mode$.pipe(filter((val) => val === "select"), take(1)).subscribe(() => {
5092
+ elementToFocus.forEach((el) => {
5093
+ Object.assign(el.style, next.style);
5094
+ });
5095
+ }));
5096
+ stylesMap.set(firstElement.getAttribute("__mia_preview_id"), styles);
5097
+ });
5098
+ return () => subscription.unsubscribe();
5099
+ }
4876
5100
  var t;
4877
5101
  const i = window, s = i.trustedTypes, e = s ? s.createPolicy("lit-html", { createHTML: (t2) => t2 }) : void 0, o = "$lit$", n = `lit$${(Math.random() + "").slice(9)}$`, l = "?" + n, h = `<${l}>`, r = document, d = () => r.createComment(""), u = (t2) => null === t2 || "object" != typeof t2 && "function" != typeof t2, c = Array.isArray, v = (t2) => c(t2) || "function" == typeof (null == t2 ? void 0 : t2[Symbol.iterator]), a = "[ \n\f\r]", f = /<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g, _ = /-->/g, m = />/g, p = RegExp(`>|${a}(?:([^\\s"'>=/]+)(${a}*=${a}*(?:[^
4878
5102
  \f\r"'\`<>=]|("|')|))|$)`, "g"), g = /'/g, $ = /"/g, y = /^(?:script|style|textarea|title)$/i, w = (t2) => (i2, ...s2) => ({ _$litType$: t2, strings: i2, values: s2 }), x = w(1), T = Symbol.for("lit-noChange"), A = Symbol.for("lit-nothing"), E = /* @__PURE__ */ new WeakMap(), C = r.createTreeWalker(r, 129, null, false), P = (t2, i2) => {
@@ -5326,7 +5550,7 @@ const __vitePreload = function preload(baseModule, deps, importerUrl) {
5326
5550
  })).then(() => baseModule());
5327
5551
  };
5328
5552
  function error(message, ...args) {
5329
- __vitePreload(() => import("./errors-5a0ccde7.js"), true ? [] : void 0, import.meta.url).then(({ default: errorMap }) => {
5553
+ __vitePreload(() => import("./assets/errors-5a0ccde7.js"), true ? [] : void 0, import.meta.url).then(({ default: errorMap }) => {
5330
5554
  const handler2 = errorMap[message];
5331
5555
  handler2 ? console.error(handler2(...args)) : console.error(...args);
5332
5556
  }).catch((err) => {
@@ -5340,12 +5564,12 @@ function dynamicImportError(name) {
5340
5564
  error("0", name, err.message);
5341
5565
  };
5342
5566
  }
5343
- const logger = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
5567
+ const logger$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
5344
5568
  __proto__: null,
5345
5569
  dynamicImportError,
5346
5570
  error
5347
5571
  }, Symbol.toStringTag, { value: "Module" }));
5348
- var logger_default = logger;
5572
+ var logger_default = logger$1;
5349
5573
  var __defProp$2 = Object.defineProperty;
5350
5574
  var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
5351
5575
  var __publicField$2 = (obj, key, value) => {
@@ -5571,60 +5795,6 @@ async function render(config2, container, context = {}) {
5571
5795
  return null;
5572
5796
  });
5573
5797
  }
5574
- function registerChannels() {
5575
- return {
5576
- configuration: new ReplaySubject(),
5577
- focus: new BehaviorSubject(void 0),
5578
- infos: new ReplaySubject(),
5579
- mocks: new ReplaySubject(),
5580
- mode: new BehaviorSubject("select"),
5581
- notification: new ReplaySubject(),
5582
- updated: new Subject(),
5583
- uppercaseTags: /* @__PURE__ */ new Set()
5584
- };
5585
- }
5586
- const nextMode = (mode) => {
5587
- let next = 0;
5588
- const currentValue = mode.getValue();
5589
- if (currentValue === "interact") {
5590
- next = "select";
5591
- } else if (currentValue === "select") {
5592
- next = "interact";
5593
- }
5594
- mode.next(next);
5595
- return next;
5596
- };
5597
- const subjects = registerChannels();
5598
- function listener(message) {
5599
- switch (message.type) {
5600
- case "options": {
5601
- const { content: { disableOverlay, redirectTo, timeout } } = message;
5602
- if (disableOverlay) {
5603
- Object.defineProperty(this.window, "__BACKOFFICE_CONFIGURATOR_DISABLE_OVERLAY__", { value: true });
5604
- subjects.mode.next("interact");
5605
- }
5606
- if (timeout !== void 0) {
5607
- Object.defineProperty(this.window, "__BACKOFFICE_CONFIGURATOR_PREVIEW_TIMEOUT__", { value: timeout });
5608
- }
5609
- const { window: { history } } = this;
5610
- redirectTo && history.pushState(history.state, "", redirectTo);
5611
- break;
5612
- }
5613
- case "ctrl-space":
5614
- nextMode(subjects.mode);
5615
- break;
5616
- case "new-configuration":
5617
- subjects.configuration.next({ ...message.content, type: "reset" });
5618
- break;
5619
- case "update":
5620
- subjects.configuration.next({ ...message.content, type: "update" });
5621
- break;
5622
- case "focus-element":
5623
- subjects.focus.next(message.content);
5624
- break;
5625
- }
5626
- }
5627
- const postChannel = new PostChannel(listener);
5628
5798
  const fromErrorToNotification = (error2) => {
5629
5799
  var _a2;
5630
5800
  return {
@@ -5760,7 +5930,9 @@ const getPreviewContainer = (frame, root) => {
5760
5930
  let container = root.firstElementChild;
5761
5931
  if (container === null) {
5762
5932
  container = document2.createElement("div");
5763
- container.style.height = "inherit";
5933
+ container.style.height = "100%";
5934
+ container.style.width = "100%";
5935
+ container.style.overflow = "auto";
5764
5936
  container.style.display = "flex";
5765
5937
  root.appendChild(container);
5766
5938
  }
@@ -6152,9 +6324,8 @@ function appendOverlay(self2, mode$) {
6152
6324
  }
6153
6325
  const appendRenderRoot = (document2) => {
6154
6326
  const renderRoot = document2.createElement("div");
6155
- renderRoot.style.display = "flex";
6156
- renderRoot.style.flexDirection = "column";
6157
6327
  renderRoot.style.height = "inherit";
6328
+ renderRoot.style.width = "inherit";
6158
6329
  document2.body.appendChild(renderRoot);
6159
6330
  return renderRoot;
6160
6331
  };
@@ -6211,7 +6382,10 @@ const addInfoFactory = (channels) => (info) => {
6211
6382
  };
6212
6383
  const run = (frame, renderRoot, channels) => {
6213
6384
  const queue = new Queue();
6214
- const subscription = channels.configuration.subscribe((next) => {
6385
+ const subscription = channels.configuration.pipe(
6386
+ combineLatestWith(subjects.swReady.pipe(take(1))),
6387
+ map(([next]) => next)
6388
+ ).subscribe((next) => {
6215
6389
  const { configuration } = next;
6216
6390
  const { content } = configuration;
6217
6391
  let done;
@@ -6297,11 +6471,51 @@ function createComposerApplication(self2, channels) {
6297
6471
  sandboxedWindow
6298
6472
  };
6299
6473
  }
6300
- const init = (self2) => {
6474
+ function logger(type, ...args) {
6475
+ {
6476
+ const color = generateDarkColorHex();
6477
+ const background = `${color}22`;
6478
+ const style = { background, color };
6479
+ console.groupCollapsed(`%c Preview ${this.location.href}`, Object.entries(style).map(([key, val]) => `${key}: ${val}`).join("; "));
6480
+ console[type](...args);
6481
+ console.groupEnd();
6482
+ }
6483
+ }
6484
+ function logServiceWorkerStatus(registration) {
6485
+ const log = logger.bind(this);
6486
+ if (registration.installing) {
6487
+ log("info", "Service worker installing");
6488
+ } else if (registration.waiting) {
6489
+ log("info", "Service worker installed");
6490
+ } else if (registration.active) {
6491
+ log("info", "Service worker active");
6492
+ }
6493
+ }
6494
+ const registerServiceWorker = async (self2) => {
6495
+ const { navigator: navigator2 } = self2;
6496
+ if ("serviceWorker" in navigator2) {
6497
+ navigator2.serviceWorker.register("./service-worker.js", { scope: "./" }).then((reg) => logServiceWorkerStatus.call(self2, reg)).catch((error2) => console.error(error2));
6498
+ return navigator2.serviceWorker.ready.then((reg) => {
6499
+ var _a2;
6500
+ return (_a2 = reg.active) != null ? _a2 : Promise.reject(new TypeError("serviceWorker not active"));
6501
+ });
6502
+ }
6503
+ logger.call(self2, "error", "serviceWorker is not available");
6504
+ };
6505
+ const init = async (self2) => {
6301
6506
  postChannel.window = self2;
6507
+ serviceWorkerChannel.window = self2;
6508
+ return registerServiceWorker(self2);
6302
6509
  };
6303
- function registerSenders(chs) {
6510
+ function registerSenders(chs, sw) {
6304
6511
  const subscription = new Subscription();
6512
+ if (sw) {
6513
+ subscription.add(
6514
+ chs.setSourceMap.subscribe(
6515
+ (next) => serviceWorkerChannel.send(sw, { content: next, type: "set-source-map" })
6516
+ )
6517
+ );
6518
+ }
6305
6519
  subscription.add(
6306
6520
  chs.updated.subscribe(() => {
6307
6521
  postChannel.send(window.parent, {
@@ -6357,10 +6571,20 @@ function registerCleanups(window2, fns) {
6357
6571
  fns.forEach((fn) => fn());
6358
6572
  });
6359
6573
  }
6360
- ((self2) => {
6361
- init(self2);
6574
+ (async (self2) => {
6575
+ const sw = await init(self2);
6576
+ let serviceWorkerChannelCleanup = noop;
6362
6577
  const postChannelCleanup = postChannel.recv(self2, self2.top);
6363
- const senderCleanup = registerSenders(subjects);
6578
+ if (sw) {
6579
+ const swCleanup = serviceWorkerChannel.recv();
6580
+ const subscription = interval(100).subscribe(() => postChannel.send(self2.parent, { content: { status: "ready" }, type: "service-worker" }));
6581
+ serviceWorkerChannelCleanup = () => {
6582
+ swCleanup();
6583
+ subscription.unsubscribe();
6584
+ serviceWorkerChannel.send(sw, { content: {}, type: "unload-client" });
6585
+ };
6586
+ }
6587
+ const senderCleanup = registerSenders(subjects, sw);
6364
6588
  const listenerCleanup = registerEventListeners(
6365
6589
  self2,
6366
6590
  { handler: ctrlSpaceFactory(subjects), type: "keydown" },
@@ -6378,7 +6602,10 @@ function registerCleanups(window2, fns) {
6378
6602
  composerApplicationCleanup,
6379
6603
  listenerCleanup,
6380
6604
  senderCleanup,
6605
+ serviceWorkerChannelCleanup,
6381
6606
  postChannelCleanup
6382
6607
  ]
6383
6608
  );
6384
- })(window);
6609
+ })(window).catch((error2) => {
6610
+ throw error2;
6611
+ });