@plaidev/karte-action-sdk 1.1.124 → 1.1.125-27947768.57120ff7

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);
@@ -928,24 +923,27 @@ function w(w) {
928
923
  */
929
924
  const logger = {
930
925
  info: (...messages) => {
931
- const log = { level: 'info', message: formatLog(messages), date: new Date() };
926
+ const log = { level: 'info', messages, date: new Date() };
932
927
  w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'log', log } }, '*');
933
928
  },
934
929
  log: (...messages) => {
935
- const log = { level: 'info', message: formatLog(messages), date: new Date() };
930
+ const log = { level: 'info', messages, date: new Date() };
936
931
  w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'log', log } }, '*');
937
932
  },
938
933
  error: (...messages) => {
939
- const log = { level: 'error', message: formatLog(messages), date: new Date() };
934
+ const log = { level: 'error', messages, date: new Date() };
940
935
  w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'log', log } }, '*');
941
936
  },
942
937
  warn: (...messages) => {
943
- const log = { level: 'warn', message: formatLog(messages), date: new Date() };
938
+ const log = { level: 'warn', messages, date: new Date() };
944
939
  w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'log', log } }, '*');
945
940
  },
946
941
  event: (name, values) => {
947
942
  const event = values ? { name, values, date: new Date() } : { name, date: new Date() };
948
- w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'event', event } }, '*');
943
+ w(window).postMessage({
944
+ type: 'KARTE-ACTION-LOGGER',
945
+ detail: { method: 'event', event, values: values },
946
+ }, '*');
949
947
  },
950
948
  clear: () => {
951
949
  w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'clear' } }, '*');
@@ -955,7 +953,7 @@ const logger = {
955
953
  },
956
954
  };
957
955
  /**
958
- * loggerのログを実行ログに表示する
956
+ * メッセージを実行ログに表示する
959
957
  */
960
958
  function listenLogger() {
961
959
  const handler = (event) => {
@@ -976,8 +974,8 @@ function listenLogger() {
976
974
  if (MESSAGES_LIMIT <= logs.length) {
977
975
  logs.shift();
978
976
  }
979
- const { level, message } = detail.log;
980
- const log = { level, message, date: new Date() };
977
+ const { level, messages } = detail.log;
978
+ const log = { level, messages, date: new Date() };
981
979
  logs.push(log);
982
980
  }
983
981
  else if (detail.method === 'event') {
@@ -1026,39 +1024,6 @@ function listenConsoleLogger() {
1026
1024
  console.warn = warn;
1027
1025
  };
1028
1026
  }
1029
- function formatLog(texts) {
1030
- if (!texts)
1031
- return '';
1032
- const s = texts
1033
- .reduce((acc, t) => {
1034
- let text = '';
1035
- try {
1036
- if (typeof t === 'string') {
1037
- text += t;
1038
- }
1039
- else if (t instanceof Error) {
1040
- text += formatError(t);
1041
- }
1042
- else {
1043
- text += JSON.stringify(t, undefined, 2);
1044
- }
1045
- }
1046
- catch (e) {
1047
- //pass
1048
- }
1049
- acc += text + ' ';
1050
- return acc;
1051
- }, '')
1052
- .trim();
1053
- return s.length > 3000 ? s.substr(0, 3000) + '...' : s;
1054
- }
1055
- function formatError(error) {
1056
- if (!error)
1057
- return '';
1058
- if (error.stack)
1059
- return error.stack;
1060
- return error.message;
1061
- }
1062
1027
 
1063
1028
  function doPresent({ direction, deltaRate }, downFn, upFn, condition = false) {
1064
1029
  if (direction === 'down' && deltaRate > 0) {
@@ -1388,6 +1353,90 @@ const FormRatingButtonTypes = ['star', 'face'];
1388
1353
  /** @internal */
1389
1354
  const DefaultFormRatingButtonType = 'star';
1390
1355
 
1356
+ const DEFAULT_COLLECTION_ENDPOINT = typeof __FLYER_GEN_COLLECTION_API_ENDPOINT__ === 'string'
1357
+ ? __FLYER_GEN_COLLECTION_API_ENDPOINT__
1358
+ : 'https://t.karte.io/collection';
1359
+ /**
1360
+ * アクションテーブルを管理するメソッドを取得する
1361
+ *
1362
+ * @param config - 設定情報
1363
+ *
1364
+ * @returns メソッドを返します
1365
+ *
1366
+ * @public
1367
+ */
1368
+ function collection$1(config) {
1369
+ const endpoint = config.endpoint || DEFAULT_COLLECTION_ENDPOINT;
1370
+ const api_key = config.api_key;
1371
+ const table = config.table;
1372
+ return {
1373
+ get(key, cb) {
1374
+ if (Array.isArray(key)) {
1375
+ return request(`${endpoint}/getByKeys`, {
1376
+ api_key,
1377
+ name: table,
1378
+ keys: key,
1379
+ }, cb);
1380
+ }
1381
+ else {
1382
+ request(`${endpoint}/getByKey`, {
1383
+ api_key,
1384
+ name: table,
1385
+ key,
1386
+ }, cb);
1387
+ }
1388
+ },
1389
+ getByQuery(query_name, params, options, cb) {
1390
+ request(`${endpoint}/getByQuery`, {
1391
+ api_key,
1392
+ name: table,
1393
+ query_name,
1394
+ params,
1395
+ options,
1396
+ }, cb);
1397
+ },
1398
+ set(key, value, cb) {
1399
+ request(`${endpoint}/set`, {
1400
+ api_key,
1401
+ name: table,
1402
+ key,
1403
+ value,
1404
+ }, cb);
1405
+ },
1406
+ };
1407
+ }
1408
+ function request(url, data, cb) {
1409
+ fetch(url, {
1410
+ method: 'POST',
1411
+ headers: {
1412
+ 'Content-Type': 'text/plain;charset=UTF-8',
1413
+ },
1414
+ body: JSON.stringify({ ...data }),
1415
+ }).then(response => {
1416
+ if (!response.ok) {
1417
+ return cb(new Error(`fail to request collection api. reason: ${response.status}`));
1418
+ }
1419
+ return cb(null, response.json());
1420
+ });
1421
+ }
1422
+ const loadActionTableRow = async (config, api_key, endpoint) => {
1423
+ 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))));
1424
+ };
1425
+ const loadActionTableRows = async (config, api_key, endpoint) => {
1426
+ 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))));
1427
+ };
1428
+ const loadActionTableQuery = async (config, api_key, endpoint) => {
1429
+ 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))));
1430
+ };
1431
+ const loadActionTable = async (config, api_key, endpoint) => {
1432
+ const results = config.map(c => c.preview_value)
1433
+ ;
1434
+ return config.reduce((acc, c, i) => {
1435
+ acc[c.name] = results[i];
1436
+ return acc;
1437
+ }, {});
1438
+ };
1439
+
1391
1440
  /**
1392
1441
  * アクションが作成 (create) される前にフックする関数
1393
1442
  *
@@ -1477,6 +1526,7 @@ function create(App, options = {
1477
1526
  send: () => { },
1478
1527
  props: {},
1479
1528
  variables: {},
1529
+ localVariablesQuery: undefined,
1480
1530
  }) {
1481
1531
  let app = null;
1482
1532
  const data = {
@@ -1489,7 +1539,7 @@ function create(App, options = {
1489
1539
  // NOTE: onCreateより前にListenする必要がある
1490
1540
  window.addEventListener(ACTION_DESTROY_EVENT, () => {
1491
1541
  const { onDestroyHandlers } = getInternalHandlers();
1492
- onDestroyHandlers && onDestroyHandlers.forEach(h => h(actionProps));
1542
+ onDestroyHandlers?.forEach(h => h(actionProps));
1493
1543
  // 複数回onDestroyを呼ばないようにする処理
1494
1544
  window.removeEventListener('beforeunload', dispatchDestroyEvent);
1495
1545
  });
@@ -1500,6 +1550,10 @@ function create(App, options = {
1500
1550
  shortenId: data.shorten_id || null,
1501
1551
  campaignId: data.campaign_id || null,
1502
1552
  });
1553
+ // ActionTable APIへの非同期リクエスト
1554
+ if (options.localVariablesQuery && data.api_key) {
1555
+ loadActionTable(options.localVariablesQuery, data.api_key).then(result => setCustomVariables(result));
1556
+ }
1503
1557
  const close = (trigger = 'none') => {
1504
1558
  if (!app) {
1505
1559
  return;
@@ -1728,7 +1782,7 @@ function createFog({ color = '#000', opacity = '50%', zIndex = 999, onclick, })
1728
1782
  */
1729
1783
  function getActionShadowRoot() {
1730
1784
  const root = document.querySelector(`.${KARTE_ACTION_ROOT}[data-${KARTE_ACTION_RID}='${actionId}']`);
1731
- if (!root || !root.shadowRoot) {
1785
+ if (!root?.shadowRoot) {
1732
1786
  return null;
1733
1787
  }
1734
1788
  return root.shadowRoot;
@@ -1761,7 +1815,7 @@ async function fixFontFaceIssue(href, cssRules) {
1761
1815
  const rules = [];
1762
1816
  const fixedRules = [];
1763
1817
  Array.from(css.cssRules).forEach(cssRule => {
1764
- if (cssRule.type != 5) {
1818
+ if (cssRule.type !== 5) {
1765
1819
  rules.push(cssRule.cssText);
1766
1820
  }
1767
1821
  // type 5 is @font-face
@@ -1871,6 +1925,7 @@ function createApp(App, options = {
1871
1925
  send: () => { },
1872
1926
  props: {},
1873
1927
  variables: {},
1928
+ localVariablesQuery: undefined,
1874
1929
  }) {
1875
1930
  let app = null;
1876
1931
  const close = () => {
@@ -1907,80 +1962,6 @@ function createApp(App, options = {
1907
1962
  };
1908
1963
  }
1909
1964
 
1910
- const DEFAULT_COLLECTION_ENDPOINT = typeof __FLYER_GEN_COLLECTION_API_ENDPOINT__ === 'string'
1911
- ? __FLYER_GEN_COLLECTION_API_ENDPOINT__
1912
- : 'https://t.karte.io/collection';
1913
- /**
1914
- * アクションテーブルを管理するメソッドを取得する
1915
- *
1916
- * @param config - 設定情報
1917
- *
1918
- * @returns メソッドを返します
1919
- *
1920
- * @public
1921
- */
1922
- function collection$1(config) {
1923
- const endpoint = config.endpoint || DEFAULT_COLLECTION_ENDPOINT;
1924
- const api_key = config.api_key;
1925
- const table = config.table;
1926
- return {
1927
- get(key, cb) {
1928
- if (Array.isArray(key)) {
1929
- return request(`${endpoint}/getByKeys`, {
1930
- api_key,
1931
- name: table,
1932
- keys: key,
1933
- }, cb);
1934
- }
1935
- else {
1936
- request(`${endpoint}/getByKey`, {
1937
- api_key,
1938
- name: table,
1939
- key,
1940
- }, cb);
1941
- }
1942
- },
1943
- getByQuery(query_name, params, options, cb) {
1944
- request(`${endpoint}/getByQuery`, {
1945
- api_key,
1946
- name: table,
1947
- query_name,
1948
- params,
1949
- options,
1950
- }, cb);
1951
- },
1952
- set(key, value, cb) {
1953
- request(`${endpoint}/set`, {
1954
- api_key,
1955
- name: table,
1956
- key,
1957
- value,
1958
- }, cb);
1959
- },
1960
- };
1961
- }
1962
- function request(url, data, cb) {
1963
- const xhr = new XMLHttpRequest();
1964
- xhr.onreadystatechange = () => {
1965
- if (xhr.readyState != 4) {
1966
- return;
1967
- }
1968
- if (xhr.status != 200) {
1969
- return cb(new Error(`fail to send collection api request. reason: ${xhr.responseText}`));
1970
- }
1971
- try {
1972
- data = JSON.parse(xhr.responseText);
1973
- return cb(null, data);
1974
- }
1975
- catch (err) {
1976
- return cb(err);
1977
- }
1978
- };
1979
- xhr.open('POST', url);
1980
- xhr.setRequestHeader('Content-Type', 'text/plain;charset=UTF-8');
1981
- xhr.send(JSON.stringify({ ...data }));
1982
- }
1983
-
1984
1965
  /**
1985
1966
  * Widget API 互換のインターフェース
1986
1967
  */
@@ -8394,4 +8375,4 @@ class ImageBlock extends SvelteComponent {
8394
8375
  }
8395
8376
  }
8396
8377
 
8397
- 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, 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 };
8378
+ 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, 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 };