@plaidev/karte-action-sdk 1.1.123 → 1.1.124-27946655.bba7dcb4

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,10 +6,6 @@ import { setContext, getContext, createEventDispatcher, onMount, onDestroy as on
6
6
  /** @internal */
7
7
  const NOOP = (_args) => { }; // eslint-disable-line @typescript-eslint/no-unused-vars
8
8
  /** @internal */
9
- const isPreview = () => {
10
- return true;
11
- };
12
- /** @internal */
13
9
  const handleFocus = (node) => (e) => {
14
10
  if (node) {
15
11
  // trap focus
@@ -288,12 +284,12 @@ const state = writable('/');
288
284
  * 現在のステートを設定する
289
285
  *
290
286
  * @param stateId - 表示するステートID
291
- * @param force - 強制的にステートを設定するフラグ。デフォルトは `false`
287
+ * @param options - オプション。`options.disableInPreview`でプレビュー時のステート遷移を無効化できます。
292
288
  *
293
289
  * @public
294
290
  */
295
- function setState$1(stateId, force = false) {
296
- if (!force && isPreview())
291
+ function setState$1(stateId, options) {
292
+ if (options?.disableInPreview)
297
293
  return;
298
294
  state.set(stateId);
299
295
  }
@@ -703,15 +699,14 @@ const ACTION_CHANGE_STATE_EVENT = `KARTE-ACTION-CHANGE-STATE-${actionId}`;
703
699
  /** @internal */
704
700
  const handleState = (event) => {
705
701
  if (event.detail.actionId === actionId || event.detail.actionId === ALL_ACTION_ID) {
706
- setState$1(event.detail.to, event.detail.force);
702
+ setState$1(event.detail.to, { disableInPreview: event.detail.disableInPreview });
707
703
  }
708
704
  };
709
705
  /** @internal */
710
706
  const initialize = (setting) => {
711
707
  const newSetting = setActionSetting(setting);
712
708
  if (newSetting.initialState) {
713
- const force = true;
714
- setState$1(setting?.initialState, force);
709
+ setState$1(setting?.initialState);
715
710
  }
716
711
  if (newSetting.autoStart) {
717
712
  setStopped(!newSetting.autoStart);
@@ -910,9 +905,15 @@ const setAutoStart = (on = true) => {
910
905
  const MESSAGES_LIMIT = 1000;
911
906
  const EVENTS_LIMIT = 1000;
912
907
  // 実行ログ
913
- let messages = [];
908
+ let logs = [];
914
909
  // KARTEイベント
915
910
  let events = [];
911
+ function getLogs() {
912
+ return logs;
913
+ }
914
+ function getEvents() {
915
+ return events;
916
+ }
916
917
  // iframe内の場合は親windowを参照する
917
918
  function w(w) {
918
919
  return w.parent === w ? w : w.parent;
@@ -935,7 +936,6 @@ const logger = {
935
936
  },
936
937
  warn: (...messages) => {
937
938
  const log = { level: 'warn', message: formatLog(messages), date: new Date() };
938
- console.log('aaaaaaaaa', w);
939
939
  w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'log', log } }, '*');
940
940
  },
941
941
  event: (name, values) => {
@@ -962,18 +962,18 @@ function listenLogger() {
962
962
  return;
963
963
  }
964
964
  if (detail.method === 'clear') {
965
- messages = [];
965
+ logs = [];
966
966
  }
967
967
  else if (detail.method === 'clearEvents') {
968
968
  events = [];
969
969
  }
970
970
  else if (detail.method === 'log') {
971
- if (MESSAGES_LIMIT <= messages.length) {
972
- messages.shift();
971
+ if (MESSAGES_LIMIT <= logs.length) {
972
+ logs.shift();
973
973
  }
974
974
  const { level, message } = detail.log;
975
975
  const log = { level, message, date: new Date() };
976
- messages.push(log);
976
+ logs.push(log);
977
977
  }
978
978
  else if (detail.method === 'event') {
979
979
  if (EVENTS_LIMIT <= events.length) {
@@ -1383,6 +1383,90 @@ const FormRatingButtonTypes = ['star', 'face'];
1383
1383
  /** @internal */
1384
1384
  const DefaultFormRatingButtonType = 'star';
1385
1385
 
1386
+ const DEFAULT_COLLECTION_ENDPOINT = typeof __FLYER_GEN_COLLECTION_API_ENDPOINT__ === 'string'
1387
+ ? __FLYER_GEN_COLLECTION_API_ENDPOINT__
1388
+ : 'https://t.karte.io/collection';
1389
+ /**
1390
+ * アクションテーブルを管理するメソッドを取得する
1391
+ *
1392
+ * @param config - 設定情報
1393
+ *
1394
+ * @returns メソッドを返します
1395
+ *
1396
+ * @public
1397
+ */
1398
+ function collection$1(config) {
1399
+ const endpoint = config.endpoint || DEFAULT_COLLECTION_ENDPOINT;
1400
+ const api_key = config.api_key;
1401
+ const table = config.table;
1402
+ return {
1403
+ get(key, cb) {
1404
+ if (Array.isArray(key)) {
1405
+ return request(`${endpoint}/getByKeys`, {
1406
+ api_key,
1407
+ name: table,
1408
+ keys: key,
1409
+ }, cb);
1410
+ }
1411
+ else {
1412
+ request(`${endpoint}/getByKey`, {
1413
+ api_key,
1414
+ name: table,
1415
+ key,
1416
+ }, cb);
1417
+ }
1418
+ },
1419
+ getByQuery(query_name, params, options, cb) {
1420
+ request(`${endpoint}/getByQuery`, {
1421
+ api_key,
1422
+ name: table,
1423
+ query_name,
1424
+ params,
1425
+ options,
1426
+ }, cb);
1427
+ },
1428
+ set(key, value, cb) {
1429
+ request(`${endpoint}/set`, {
1430
+ api_key,
1431
+ name: table,
1432
+ key,
1433
+ value,
1434
+ }, cb);
1435
+ },
1436
+ };
1437
+ }
1438
+ function request(url, data, cb) {
1439
+ fetch(url, {
1440
+ method: 'POST',
1441
+ headers: {
1442
+ 'Content-Type': 'text/plain;charset=UTF-8',
1443
+ },
1444
+ body: JSON.stringify({ ...data }),
1445
+ }).then(response => {
1446
+ if (!response.ok) {
1447
+ return cb(new Error(`fail to request collection api. reason: ${response.status}`));
1448
+ }
1449
+ return cb(null, response.json());
1450
+ });
1451
+ }
1452
+ const loadActionTableRow = async (config, api_key, endpoint) => {
1453
+ return new Promise((resolve, reject) => collection$1({ endpoint, api_key, table: config.default.table_name }).get(config.default.key, (err, data) => (err ? reject(err) : resolve(data))));
1454
+ };
1455
+ const loadActionTableRows = async (config, api_key, endpoint) => {
1456
+ return new Promise((resolve, reject) => collection$1({ endpoint, api_key, table: config.default.table_name }).get(config.default.key, (err, data) => (err ? reject(err) : resolve(data))));
1457
+ };
1458
+ const loadActionTableQuery = async (config, api_key, endpoint) => {
1459
+ return new Promise((resolve, reject) => collection$1({ endpoint, api_key, table: config.default.table_name }).getByQuery(config.default.query_name, config.default.params, null, (err, data) => (err ? reject(err) : resolve(data))));
1460
+ };
1461
+ const loadActionTable = async (config, api_key, endpoint) => {
1462
+ const results = config.map(c => c.preview_value)
1463
+ ;
1464
+ return config.reduce((acc, c, i) => {
1465
+ acc[c.name] = results[i];
1466
+ return acc;
1467
+ }, {});
1468
+ };
1469
+
1386
1470
  /**
1387
1471
  * アクションが作成 (create) される前にフックする関数
1388
1472
  *
@@ -1472,6 +1556,7 @@ function create(App, options = {
1472
1556
  send: () => { },
1473
1557
  props: {},
1474
1558
  variables: {},
1559
+ localVariablesQuery: undefined,
1475
1560
  }) {
1476
1561
  let app = null;
1477
1562
  const data = {
@@ -1484,7 +1569,7 @@ function create(App, options = {
1484
1569
  // NOTE: onCreateより前にListenする必要がある
1485
1570
  window.addEventListener(ACTION_DESTROY_EVENT, () => {
1486
1571
  const { onDestroyHandlers } = getInternalHandlers();
1487
- onDestroyHandlers && onDestroyHandlers.forEach(h => h(actionProps));
1572
+ onDestroyHandlers?.forEach(h => h(actionProps));
1488
1573
  // 複数回onDestroyを呼ばないようにする処理
1489
1574
  window.removeEventListener('beforeunload', dispatchDestroyEvent);
1490
1575
  });
@@ -1495,6 +1580,10 @@ function create(App, options = {
1495
1580
  shortenId: data.shorten_id || null,
1496
1581
  campaignId: data.campaign_id || null,
1497
1582
  });
1583
+ // ActionTable APIへの非同期リクエスト
1584
+ if (options.localVariablesQuery && data.api_key) {
1585
+ loadActionTable(options.localVariablesQuery, data.api_key).then(result => setCustomVariables(result));
1586
+ }
1498
1587
  const close = (trigger = 'none') => {
1499
1588
  if (!app) {
1500
1589
  return;
@@ -1723,7 +1812,7 @@ function createFog({ color = '#000', opacity = '50%', zIndex = 999, onclick, })
1723
1812
  */
1724
1813
  function getActionShadowRoot() {
1725
1814
  const root = document.querySelector(`.${KARTE_ACTION_ROOT}[data-${KARTE_ACTION_RID}='${actionId}']`);
1726
- if (!root || !root.shadowRoot) {
1815
+ if (!root?.shadowRoot) {
1727
1816
  return null;
1728
1817
  }
1729
1818
  return root.shadowRoot;
@@ -1756,7 +1845,7 @@ async function fixFontFaceIssue(href, cssRules) {
1756
1845
  const rules = [];
1757
1846
  const fixedRules = [];
1758
1847
  Array.from(css.cssRules).forEach(cssRule => {
1759
- if (cssRule.type != 5) {
1848
+ if (cssRule.type !== 5) {
1760
1849
  rules.push(cssRule.cssText);
1761
1850
  }
1762
1851
  // type 5 is @font-face
@@ -1866,6 +1955,7 @@ function createApp(App, options = {
1866
1955
  send: () => { },
1867
1956
  props: {},
1868
1957
  variables: {},
1958
+ localVariablesQuery: undefined,
1869
1959
  }) {
1870
1960
  let app = null;
1871
1961
  const close = () => {
@@ -1902,80 +1992,6 @@ function createApp(App, options = {
1902
1992
  };
1903
1993
  }
1904
1994
 
1905
- const DEFAULT_COLLECTION_ENDPOINT = typeof __FLYER_GEN_COLLECTION_API_ENDPOINT__ === 'string'
1906
- ? __FLYER_GEN_COLLECTION_API_ENDPOINT__
1907
- : 'https://t.karte.io/collection';
1908
- /**
1909
- * アクションテーブルを管理するメソッドを取得する
1910
- *
1911
- * @param config - 設定情報
1912
- *
1913
- * @returns メソッドを返します
1914
- *
1915
- * @public
1916
- */
1917
- function collection$1(config) {
1918
- const endpoint = config.endpoint || DEFAULT_COLLECTION_ENDPOINT;
1919
- const api_key = config.api_key;
1920
- const table = config.table;
1921
- return {
1922
- get(key, cb) {
1923
- if (Array.isArray(key)) {
1924
- return request(`${endpoint}/getByKeys`, {
1925
- api_key,
1926
- name: table,
1927
- keys: key,
1928
- }, cb);
1929
- }
1930
- else {
1931
- request(`${endpoint}/getByKey`, {
1932
- api_key,
1933
- name: table,
1934
- key,
1935
- }, cb);
1936
- }
1937
- },
1938
- getByQuery(query_name, params, options, cb) {
1939
- request(`${endpoint}/getByQuery`, {
1940
- api_key,
1941
- name: table,
1942
- query_name,
1943
- params,
1944
- options,
1945
- }, cb);
1946
- },
1947
- set(key, value, cb) {
1948
- request(`${endpoint}/set`, {
1949
- api_key,
1950
- name: table,
1951
- key,
1952
- value,
1953
- }, cb);
1954
- },
1955
- };
1956
- }
1957
- function request(url, data, cb) {
1958
- const xhr = new XMLHttpRequest();
1959
- xhr.onreadystatechange = () => {
1960
- if (xhr.readyState != 4) {
1961
- return;
1962
- }
1963
- if (xhr.status != 200) {
1964
- return cb(new Error(`fail to send collection api request. reason: ${xhr.responseText}`));
1965
- }
1966
- try {
1967
- data = JSON.parse(xhr.responseText);
1968
- return cb(null, data);
1969
- }
1970
- catch (err) {
1971
- return cb(err);
1972
- }
1973
- };
1974
- xhr.open('POST', url);
1975
- xhr.setRequestHeader('Content-Type', 'text/plain;charset=UTF-8');
1976
- xhr.send(JSON.stringify({ ...data }));
1977
- }
1978
-
1979
1995
  /**
1980
1996
  * Widget API 互換のインターフェース
1981
1997
  */
@@ -8389,4 +8405,4 @@ class ImageBlock extends SvelteComponent {
8389
8405
  }
8390
8406
  }
8391
8407
 
8392
- export { Alignments, AnimationStyles, BackgroundSizes, ClipPaths, Cursors, DefaultFormButtonStyle, DefaultFormRatingButtonType, DefaultFormSelectStyle, DefaultListBackground, DefaultListBackgroundNone, DefaultListBackgroundStripe, DefaultListSeparator, DefaultListSeparatorBorder, DefaultListSeparatorGap, DefaultListSeparatorNone, DefaultModalPlacement, DefaultSlideButton, DefaultSlideNavigationButton, Directions, Elasticities, ElasticityStyle, EmbedElement, Flex, FlexItem, FormCheckBoxes, FormRadioButtons, FormRatingButtonTypes, FormRatingButtons, FormSelect, FormTextarea, Grid, GridItem, GridModalState, ImageBlock, ImageElement, Justifies, KARTE_MODAL_ROOT, LengthUnits, List, ListBackgroundTypes, ListDirections, ListItem, ListSeparatorTypes, MediaQueries, Modal, ModalPositions, MovieVimeoElement, MovieYouTubeElement, ObjectFits, OnClickOperationOptions, Overflows, PropTypes, Repeats, Slide, SlideItem, State, StateItem, TextBlock, TextButtonBlock, TextButtonElement, TextDirections, TextElement, WritingModes, applyCss, applyGlobalCss, close, closeAction, closed, collection$1 as collection, create, createApp, createFog, customHandlers, customVariables, destroy, destroyed, ensureModalRoot, events, finalize, formData, getActionShadowRoot, getCustomHandlers, getCustomVariables, getState$1 as getState, getStates, getStoreState, getSystem, hideOnScroll, hideOnTime, initialize, isClosed, isOpened, listenConsoleLogger, listenLogger, loadGlobalScript, loadGlobalStyle, loadStyle, logger, messages, onChangeState, onClose, onCreate, onDestroy, onScroll, onShow, onTime, opened, setActionSetting, setAutoStart, setClosed, setCustomHandlers, setCustomVariables, setState$1 as setState, show, showAction, showModal, showOnScroll, showOnTime, state, stopped, updateCustomHandlers, updateCustomVariables, widget };
8408
+ export { Alignments, AnimationStyles, BackgroundSizes, ClipPaths, Cursors, DefaultFormButtonStyle, DefaultFormRatingButtonType, DefaultFormSelectStyle, DefaultListBackground, DefaultListBackgroundNone, DefaultListBackgroundStripe, DefaultListSeparator, DefaultListSeparatorBorder, DefaultListSeparatorGap, DefaultListSeparatorNone, DefaultModalPlacement, DefaultSlideButton, DefaultSlideNavigationButton, Directions, Elasticities, ElasticityStyle, EmbedElement, Flex, FlexItem, FormCheckBoxes, FormRadioButtons, FormRatingButtonTypes, FormRatingButtons, FormSelect, FormTextarea, Grid, GridItem, GridModalState, ImageBlock, ImageElement, Justifies, KARTE_MODAL_ROOT, LengthUnits, List, ListBackgroundTypes, ListDirections, ListItem, ListSeparatorTypes, MediaQueries, Modal, ModalPositions, MovieVimeoElement, MovieYouTubeElement, ObjectFits, OnClickOperationOptions, Overflows, PropTypes, Repeats, Slide, SlideItem, State, StateItem, TextBlock, TextButtonBlock, TextButtonElement, TextDirections, TextElement, WritingModes, applyCss, applyGlobalCss, close, closeAction, closed, collection$1 as collection, create, createApp, createFog, customHandlers, customVariables, destroy, destroyed, ensureModalRoot, finalize, formData, getActionShadowRoot, getCustomHandlers, getCustomVariables, getEvents, getLogs, getState$1 as getState, getStates, getStoreState, getSystem, hideOnScroll, hideOnTime, initialize, isClosed, isOpened, listenConsoleLogger, listenLogger, loadActionTable, loadActionTableQuery, loadActionTableRow, loadActionTableRows, loadGlobalScript, loadGlobalStyle, loadStyle, logger, onChangeState, onClose, onCreate, onDestroy, onScroll, onShow, onTime, opened, setActionSetting, setAutoStart, setClosed, setCustomHandlers, setCustomVariables, setState$1 as setState, show, showAction, showModal, showOnScroll, showOnTime, state, stopped, updateCustomHandlers, updateCustomVariables, widget };