@plaidev/karte-action-sdk 1.1.267 → 1.1.268

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.
@@ -38,9 +38,15 @@ const KARTE_MODAL_ROOT = 'karte-modal-root';
38
38
  /** @internal */
39
39
  const NOOP = (_args) => { }; // eslint-disable-line @typescript-eslint/no-unused-vars
40
40
  /** @internal */
41
- const isPreview = () => {
42
- return false;
43
- };
41
+ const isPreview = () => (isInFrame() );
42
+ const isCanvasPreview = () => typeof document !== 'undefined'
43
+ ? (document?.querySelector('#preview')?.getAttribute('data-canvas-preview') ?? 'false') ===
44
+ 'true'
45
+ : false;
46
+ const isOnSite = () => typeof document !== 'undefined'
47
+ ? (document?.querySelector('#preview')?.getAttribute('data-on-site') ?? 'true') === 'true'
48
+ : true;
49
+ const isInFrame = () => window && window.self !== window.top;
44
50
  /** @internal */
45
51
  const setPreviousFocus = () => {
46
52
  const previously_focused = typeof document !== 'undefined' && document.activeElement;
@@ -758,6 +764,8 @@ const state = writable('/');
758
764
  * @public
759
765
  */
760
766
  function setState$1(stateId, options) {
767
+ if (isPreview() && options?.disableInPreview)
768
+ return;
761
769
  state.set(stateId);
762
770
  }
763
771
  /**
@@ -1168,7 +1176,9 @@ function cloneToJson(data) {
1168
1176
 
1169
1177
  // prettier-ignore
1170
1178
  /** @internal */
1171
- const actionId = typeof __FLYER_GEN_ACTION_ID_ON_BUILD__ === 'string'
1179
+ const actionId = isPreview()
1180
+ ? ALL_ACTION_ID
1181
+ : typeof __FLYER_GEN_ACTION_ID_ON_BUILD__ === 'string'
1172
1182
  ? __FLYER_GEN_ACTION_ID_ON_BUILD__
1173
1183
  : randStr();
1174
1184
  /** @internal */
@@ -1576,7 +1586,9 @@ const loadActionTableQuery = async (config, data, api_key, collection_endpoint)
1576
1586
  /** @internal */
1577
1587
  const loadActionTable = async (config, data, api_key, collection_endpoint) => {
1578
1588
  console.debug('[debug] loadActionTable', isPreview(), api_key, collection_endpoint, JSON.stringify(config));
1579
- const results = await Promise.all(config
1589
+ const results = isPreview()
1590
+ ? config.map(c => c.preview_value)
1591
+ : await Promise.all(config
1580
1592
  .filter(c => c.resolver === 'action-table-row' ||
1581
1593
  c.resolver === 'action-table-rows' ||
1582
1594
  c.resolver === 'action-table-query')
@@ -2302,7 +2314,7 @@ function getActionRoot() {
2302
2314
  return root.shadowRoot;
2303
2315
  }
2304
2316
  /** @internal */
2305
- function ensureActionRoot() {
2317
+ function ensureActionRoot(useShadow = true) {
2306
2318
  const systemConfig = getSystem();
2307
2319
  const rootAttrs = {
2308
2320
  class: `${KARTE_ACTION_ROOT} ${KARTE_MODAL_ROOT}`,
@@ -2317,7 +2329,7 @@ function ensureActionRoot() {
2317
2329
  el = h('div', rootAttrs);
2318
2330
  document.body.appendChild(el);
2319
2331
  }
2320
- const isShadow = !!document.body.attachShadow;
2332
+ const isShadow = !!document.body.attachShadow && useShadow;
2321
2333
  if (isShadow) {
2322
2334
  return el.shadowRoot ?? el.attachShadow({ mode: 'open' });
2323
2335
  }
@@ -2386,7 +2398,7 @@ function createApp(App, options = {
2386
2398
  },
2387
2399
  },
2388
2400
  };
2389
- const win = ensureModalRoot();
2401
+ const win = ensureModalRoot(true);
2390
2402
  appArgs.target = win;
2391
2403
  return {
2392
2404
  close,
@@ -2906,7 +2918,10 @@ function Header($$anchor, $$props) {
2906
2918
  $fonts()
2907
2919
  ),
2908
2920
  () => {
2909
- if ($fonts().length > 0) {
2921
+ if (isPreview()) {
2922
+ // フォントのロードが遅れてエディタのプレビューがガタつく対策
2923
+ $.set(googleFontUrl, makeGoogleFontUrl(Fonts.filter((font) => font !== SYSTEM_FONT)));
2924
+ } else if ($fonts().length > 0) {
2910
2925
  $.set(googleFontUrl, makeGoogleFontUrl($fonts()));
2911
2926
  }
2912
2927
  }
@@ -3477,6 +3492,9 @@ const EASING = {
3477
3492
  * @internal
3478
3493
  */
3479
3494
  function customAnimation(node, { transforms, animationStyle, delay = 0, duration = 1000 }) {
3495
+ if (!isOnSite()) {
3496
+ return {};
3497
+ }
3480
3498
  let [x, y] = [0, 0];
3481
3499
  for (const { query, x: tx, y: ty } of transforms) {
3482
3500
  if (query == null || window.matchMedia(query).matches) {
@@ -6357,7 +6375,6 @@ function Modal($$anchor, $$props) {
6357
6375
  let closeEventValue = $.prop($$props, 'closeEventValue', 8, null);
6358
6376
  let layerId = $.prop($$props, 'layerId', 8, '');
6359
6377
  const { brandKit } = useBrandKit();
6360
- const isCanvasPreview = (document.querySelector('#preview')?.getAttribute('data-canvas-preview') ?? 'false') === 'true';
6361
6378
  // モーダル背景の設定
6362
6379
  const isExistBackgroundOverlayValue = placement() && placement().backgroundOverlay !== undefined;
6363
6380
  let backgroundOverlay = $.mutable_state(DefaultModalPlacement.backgroundOverlay);
@@ -6403,7 +6420,7 @@ function Modal($$anchor, $$props) {
6403
6420
  $.deep_read_state(breakPoint())
6404
6421
  ),
6405
6422
  () => {
6406
- if (!isCanvasPreview && isExistBackgroundOverlayValue) {
6423
+ if (!isCanvasPreview() && isExistBackgroundOverlayValue) {
6407
6424
  $.set(backgroundOverlay, placement().backgroundOverlay);
6408
6425
  }
6409
6426
 
@@ -6509,7 +6526,7 @@ function Modal($$anchor, $$props) {
6509
6526
  // 表示位置のスタイルの設定
6510
6527
  let position = DefaultModalPlacement.position;
6511
6528
 
6512
- if (!isCanvasPreview && placement() && placement().position !== null) {
6529
+ if (!isCanvasPreview() && placement() && placement().position !== null) {
6513
6530
  position = placement().position;
6514
6531
  }
6515
6532
 
@@ -6526,7 +6543,7 @@ function Modal($$anchor, $$props) {
6526
6543
  $.set(transforms, []);
6527
6544
 
6528
6545
  DEVICE_IDS.forEach((deviceId) => {
6529
- if (!isCanvasPreview && useBreakPoint()) {
6546
+ if (!isCanvasPreview() && useBreakPoint()) {
6530
6547
  const positionWithBp = breakPoint()[deviceId]?.placement?.position;
6531
6548
 
6532
6549
  $.get(transforms).push({
@@ -6562,7 +6579,7 @@ function Modal($$anchor, $$props) {
6562
6579
  () => {
6563
6580
  let margin = DefaultModalPlacement.margin;
6564
6581
 
6565
- if (!isCanvasPreview && placement() && placement().margin !== null) {
6582
+ if (!isCanvasPreview() && placement() && placement().margin !== null) {
6566
6583
  margin = placement().margin;
6567
6584
  }
6568
6585
 
@@ -6573,7 +6590,7 @@ function Modal($$anchor, $$props) {
6573
6590
  }
6574
6591
 
6575
6592
  DEVICE_IDS.forEach((deviceId) => {
6576
- if (!isCanvasPreview && useBreakPoint()) {
6593
+ if (!isCanvasPreview() && useBreakPoint()) {
6577
6594
  const marginWithBp = breakPoint()[deviceId]?.placement?.margin;
6578
6595
 
6579
6596
  marginStyle = getMarginStyle(marginWithBp);
@@ -6687,7 +6704,7 @@ function Modal($$anchor, $$props) {
6687
6704
  };
6688
6705
 
6689
6706
  $.if(node, ($$render) => {
6690
- if (isCanvasPreview) $$render(consequent); else $$render(alternate, false);
6707
+ if (isCanvasPreview()) $$render(consequent); else $$render(alternate, false);
6691
6708
  });
6692
6709
  }
6693
6710
 
@@ -38,9 +38,15 @@ const KARTE_MODAL_ROOT = 'karte-modal-root';
38
38
  /** @internal */
39
39
  const NOOP = (_args) => { }; // eslint-disable-line @typescript-eslint/no-unused-vars
40
40
  /** @internal */
41
- const isPreview = () => {
42
- return false;
43
- };
41
+ const isPreview = () => (isInFrame() );
42
+ const isCanvasPreview = () => typeof document !== 'undefined'
43
+ ? (document?.querySelector('#preview')?.getAttribute('data-canvas-preview') ?? 'false') ===
44
+ 'true'
45
+ : false;
46
+ const isOnSite = () => typeof document !== 'undefined'
47
+ ? (document?.querySelector('#preview')?.getAttribute('data-on-site') ?? 'true') === 'true'
48
+ : true;
49
+ const isInFrame = () => window && window.self !== window.top;
44
50
  /** @internal */
45
51
  const setPreviousFocus = () => {
46
52
  const previously_focused = typeof document !== 'undefined' && document.activeElement;
@@ -758,6 +764,8 @@ const state = writable('/');
758
764
  * @public
759
765
  */
760
766
  function setState$1(stateId, options) {
767
+ if (isPreview() && options?.disableInPreview)
768
+ return;
761
769
  state.set(stateId);
762
770
  }
763
771
  /**
@@ -1168,7 +1176,9 @@ function cloneToJson(data) {
1168
1176
 
1169
1177
  // prettier-ignore
1170
1178
  /** @internal */
1171
- const actionId = typeof __FLYER_GEN_ACTION_ID_ON_BUILD__ === 'string'
1179
+ const actionId = isPreview()
1180
+ ? ALL_ACTION_ID
1181
+ : typeof __FLYER_GEN_ACTION_ID_ON_BUILD__ === 'string'
1172
1182
  ? __FLYER_GEN_ACTION_ID_ON_BUILD__
1173
1183
  : randStr();
1174
1184
  /** @internal */
@@ -1576,7 +1586,9 @@ const loadActionTableQuery = async (config, data, api_key, collection_endpoint)
1576
1586
  /** @internal */
1577
1587
  const loadActionTable = async (config, data, api_key, collection_endpoint) => {
1578
1588
  console.debug('[debug] loadActionTable', isPreview(), api_key, collection_endpoint, JSON.stringify(config));
1579
- const results = await Promise.all(config
1589
+ const results = isPreview()
1590
+ ? config.map(c => c.preview_value)
1591
+ : await Promise.all(config
1580
1592
  .filter(c => c.resolver === 'action-table-row' ||
1581
1593
  c.resolver === 'action-table-rows' ||
1582
1594
  c.resolver === 'action-table-query')
@@ -2302,7 +2314,7 @@ function getActionRoot() {
2302
2314
  return root.shadowRoot;
2303
2315
  }
2304
2316
  /** @internal */
2305
- function ensureActionRoot() {
2317
+ function ensureActionRoot(useShadow = true) {
2306
2318
  const systemConfig = getSystem();
2307
2319
  const rootAttrs = {
2308
2320
  class: `${KARTE_ACTION_ROOT} ${KARTE_MODAL_ROOT}`,
@@ -2317,7 +2329,7 @@ function ensureActionRoot() {
2317
2329
  el = h('div', rootAttrs);
2318
2330
  document.body.appendChild(el);
2319
2331
  }
2320
- const isShadow = !!document.body.attachShadow;
2332
+ const isShadow = !!document.body.attachShadow && useShadow;
2321
2333
  if (isShadow) {
2322
2334
  return el.shadowRoot ?? el.attachShadow({ mode: 'open' });
2323
2335
  }
@@ -2386,7 +2398,7 @@ function createApp(App, options = {
2386
2398
  },
2387
2399
  },
2388
2400
  };
2389
- const win = ensureModalRoot();
2401
+ const win = ensureModalRoot(true);
2390
2402
  appArgs.target = win;
2391
2403
  return {
2392
2404
  close,
@@ -2906,7 +2918,10 @@ function Header($$anchor, $$props) {
2906
2918
  $fonts()
2907
2919
  ),
2908
2920
  () => {
2909
- if ($fonts().length > 0) {
2921
+ if (isPreview()) {
2922
+ // フォントのロードが遅れてエディタのプレビューがガタつく対策
2923
+ $.set(googleFontUrl, makeGoogleFontUrl(Fonts.filter((font) => font !== SYSTEM_FONT)));
2924
+ } else if ($fonts().length > 0) {
2910
2925
  $.set(googleFontUrl, makeGoogleFontUrl($fonts()));
2911
2926
  }
2912
2927
  }
@@ -3477,6 +3492,9 @@ const EASING = {
3477
3492
  * @internal
3478
3493
  */
3479
3494
  function customAnimation(node, { transforms, animationStyle, delay = 0, duration = 1000 }) {
3495
+ if (!isOnSite()) {
3496
+ return {};
3497
+ }
3480
3498
  let [x, y] = [0, 0];
3481
3499
  for (const { query, x: tx, y: ty } of transforms) {
3482
3500
  if (query == null || window.matchMedia(query).matches) {
@@ -6357,7 +6375,6 @@ function Modal($$anchor, $$props) {
6357
6375
  let closeEventValue = $.prop($$props, 'closeEventValue', 8, null);
6358
6376
  let layerId = $.prop($$props, 'layerId', 8, '');
6359
6377
  const { brandKit } = useBrandKit();
6360
- const isCanvasPreview = (document.querySelector('#preview')?.getAttribute('data-canvas-preview') ?? 'false') === 'true';
6361
6378
  // モーダル背景の設定
6362
6379
  const isExistBackgroundOverlayValue = placement() && placement().backgroundOverlay !== undefined;
6363
6380
  let backgroundOverlay = $.mutable_state(DefaultModalPlacement.backgroundOverlay);
@@ -6403,7 +6420,7 @@ function Modal($$anchor, $$props) {
6403
6420
  $.deep_read_state(breakPoint())
6404
6421
  ),
6405
6422
  () => {
6406
- if (!isCanvasPreview && isExistBackgroundOverlayValue) {
6423
+ if (!isCanvasPreview() && isExistBackgroundOverlayValue) {
6407
6424
  $.set(backgroundOverlay, placement().backgroundOverlay);
6408
6425
  }
6409
6426
 
@@ -6509,7 +6526,7 @@ function Modal($$anchor, $$props) {
6509
6526
  // 表示位置のスタイルの設定
6510
6527
  let position = DefaultModalPlacement.position;
6511
6528
 
6512
- if (!isCanvasPreview && placement() && placement().position !== null) {
6529
+ if (!isCanvasPreview() && placement() && placement().position !== null) {
6513
6530
  position = placement().position;
6514
6531
  }
6515
6532
 
@@ -6526,7 +6543,7 @@ function Modal($$anchor, $$props) {
6526
6543
  $.set(transforms, []);
6527
6544
 
6528
6545
  DEVICE_IDS.forEach((deviceId) => {
6529
- if (!isCanvasPreview && useBreakPoint()) {
6546
+ if (!isCanvasPreview() && useBreakPoint()) {
6530
6547
  const positionWithBp = breakPoint()[deviceId]?.placement?.position;
6531
6548
 
6532
6549
  $.get(transforms).push({
@@ -6562,7 +6579,7 @@ function Modal($$anchor, $$props) {
6562
6579
  () => {
6563
6580
  let margin = DefaultModalPlacement.margin;
6564
6581
 
6565
- if (!isCanvasPreview && placement() && placement().margin !== null) {
6582
+ if (!isCanvasPreview() && placement() && placement().margin !== null) {
6566
6583
  margin = placement().margin;
6567
6584
  }
6568
6585
 
@@ -6573,7 +6590,7 @@ function Modal($$anchor, $$props) {
6573
6590
  }
6574
6591
 
6575
6592
  DEVICE_IDS.forEach((deviceId) => {
6576
- if (!isCanvasPreview && useBreakPoint()) {
6593
+ if (!isCanvasPreview() && useBreakPoint()) {
6577
6594
  const marginWithBp = breakPoint()[deviceId]?.placement?.margin;
6578
6595
 
6579
6596
  marginStyle = getMarginStyle(marginWithBp);
@@ -6687,7 +6704,7 @@ function Modal($$anchor, $$props) {
6687
6704
  };
6688
6705
 
6689
6706
  $.if(node, ($$render) => {
6690
- if (isCanvasPreview) $$render(consequent); else $$render(alternate, false);
6707
+ if (isCanvasPreview()) $$render(consequent); else $$render(alternate, false);
6691
6708
  });
6692
6709
  }
6693
6710
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plaidev/karte-action-sdk",
3
- "version": "1.1.267",
3
+ "version": "1.1.268",
4
4
  "author": "Plaid Inc.",
5
5
  "license": "Apache-2.0",
6
6
  "module": "./dist/index.es.js",