@plaidev/karte-action-sdk 1.1.179-28041798.8342584c → 1.1.180-28041937.24d05b80
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/dist/hydrate/index.es.d.ts +176 -82
- package/dist/hydrate/index.es.js +371 -303
- package/dist/index.es.d.ts +176 -82
- package/dist/index.es.js +424 -356
- package/dist/templates.cjs.js +2 -1
- package/dist/templates.js +2 -1
- package/package.json +2 -2
package/dist/hydrate/index.es.js
CHANGED
@@ -275,10 +275,6 @@ const NOOP = (_args) => { }; // eslint-disable-line @typescript-eslint/no-unused
|
|
275
275
|
const isPreview = () => {
|
276
276
|
return true;
|
277
277
|
};
|
278
|
-
// prettier-ignore
|
279
|
-
/** @internal */
|
280
|
-
const actionId = ALL_ACTION_ID
|
281
|
-
;
|
282
278
|
/** @internal */
|
283
279
|
const setPreviousFocus = () => {
|
284
280
|
const previously_focused = typeof document !== 'undefined' && document.activeElement;
|
@@ -1035,6 +1031,47 @@ function cloneToJson(data) {
|
|
1035
1031
|
}
|
1036
1032
|
}
|
1037
1033
|
|
1034
|
+
// prettier-ignore
|
1035
|
+
/** @internal */
|
1036
|
+
const actionId = ALL_ACTION_ID
|
1037
|
+
;
|
1038
|
+
/** @internal */
|
1039
|
+
const ACTION_DESTROY_EVENT = `KARTE-ACTION-DESTROY-${actionId}`;
|
1040
|
+
/** @internal */
|
1041
|
+
const ACTION_SHOW_EVENT = `KARTE-ACTION-SHOW-${actionId}`;
|
1042
|
+
/** @internal */
|
1043
|
+
const ACTION_CLOSE_EVENT = `KARTE-ACTION-CLOSE-${actionId}`;
|
1044
|
+
/** @internal */
|
1045
|
+
const ACTION_CHANGE_STATE_EVENT = `KARTE-ACTION-CHANGE-STATE-${actionId}`;
|
1046
|
+
/** @internal */
|
1047
|
+
const send_event = (event_name, values) => {
|
1048
|
+
const setting = getSetting();
|
1049
|
+
setting?.send?.(event_name, values);
|
1050
|
+
};
|
1051
|
+
/** @internal */
|
1052
|
+
const initialize = (setting) => {
|
1053
|
+
const newSetting = setSetting(setting);
|
1054
|
+
if (newSetting.initialState) {
|
1055
|
+
setState$1(newSetting.initialState);
|
1056
|
+
}
|
1057
|
+
setOpened(true);
|
1058
|
+
setClosed(false); // deprecated
|
1059
|
+
return () => finalize();
|
1060
|
+
};
|
1061
|
+
/** @internal */
|
1062
|
+
const finalize = () => {
|
1063
|
+
resetSetting();
|
1064
|
+
};
|
1065
|
+
/**
|
1066
|
+
* Dispatch the event to destroy KARTE action
|
1067
|
+
*
|
1068
|
+
* @internal
|
1069
|
+
*/
|
1070
|
+
function dispatchDestroyEvent() {
|
1071
|
+
const event = new CustomEvent(ACTION_DESTROY_EVENT);
|
1072
|
+
window.dispatchEvent(event);
|
1073
|
+
}
|
1074
|
+
|
1038
1075
|
/**
|
1039
1076
|
* モーダル(ポップアップ)のロジックを管理する
|
1040
1077
|
*/
|
@@ -1130,20 +1167,6 @@ function showOnTime(props, show = NOOP) {
|
|
1130
1167
|
: null;
|
1131
1168
|
}
|
1132
1169
|
|
1133
|
-
/** @internal */
|
1134
|
-
const ACTION_DESTROY_EVENT = `KARTE-ACTION-DESTROY-${actionId}`;
|
1135
|
-
/** @internal */
|
1136
|
-
const ACTION_SHOW_EVENT = `KARTE-ACTION-SHOW-${actionId}`;
|
1137
|
-
/** @internal */
|
1138
|
-
const ACTION_CLOSE_EVENT = `KARTE-ACTION-CLOSE-${actionId}`;
|
1139
|
-
/** @internal */
|
1140
|
-
const ACTION_CHANGE_STATE_EVENT = `KARTE-ACTION-CHANGE-STATE-${actionId}`;
|
1141
|
-
/** @internal */
|
1142
|
-
const send_event = (event_name, values) => {
|
1143
|
-
const setting = getSetting();
|
1144
|
-
setting?.send?.(event_name, values);
|
1145
|
-
};
|
1146
|
-
|
1147
1170
|
/**
|
1148
1171
|
* アクションテーブルに関連するコードの管理
|
1149
1172
|
*/
|
@@ -1199,6 +1222,7 @@ function collection$1(config) {
|
|
1199
1222
|
},
|
1200
1223
|
};
|
1201
1224
|
}
|
1225
|
+
/** @internal */
|
1202
1226
|
function request(url, data, cb) {
|
1203
1227
|
console.debug('[debug] request', isPreview(), url, JSON.stringify(data));
|
1204
1228
|
fetch(url, {
|
@@ -1226,6 +1250,7 @@ const loadActionTableRows = async (config, api_key, endpoint) => {
|
|
1226
1250
|
const loadActionTableQuery = async (config, api_key, endpoint) => {
|
1227
1251
|
return new Promise((resolve, reject) => collection$1({ endpoint, api_key, table: config.query.table_name }).getByQuery(config.query.query_name, config.query.params, null, (err, data) => (err ? reject(err) : resolve(data))));
|
1228
1252
|
};
|
1253
|
+
/** @internal */
|
1229
1254
|
const loadActionTable = async (config, api_key, endpoint) => {
|
1230
1255
|
console.debug('[debug] loadActionTable', isPreview(), api_key, endpoint, JSON.stringify(config));
|
1231
1256
|
const results = config.map(c => c.preview_value)
|
@@ -1238,13 +1263,23 @@ const loadActionTable = async (config, api_key, endpoint) => {
|
|
1238
1263
|
return acc;
|
1239
1264
|
}, {});
|
1240
1265
|
};
|
1266
|
+
/** @internal */
|
1267
|
+
async function setupActionTable(localVariablesQuery, apiKey) {
|
1268
|
+
const result = await loadActionTable(localVariablesQuery, apiKey);
|
1269
|
+
let success = false;
|
1270
|
+
if (Object.keys(result).length === localVariablesQuery.length) {
|
1271
|
+
setVariables(result);
|
1272
|
+
success = true;
|
1273
|
+
}
|
1274
|
+
return {
|
1275
|
+
success,
|
1276
|
+
};
|
1277
|
+
}
|
1241
1278
|
|
1242
1279
|
/**
|
1243
|
-
*
|
1244
|
-
*
|
1245
|
-
* アクションのCreate, Destroyの状態はここで管理する。
|
1280
|
+
* モーダル(ポップアップ)に関連するコードの管理
|
1246
1281
|
*
|
1247
|
-
*
|
1282
|
+
* アクションのShow, Close, ChangeStateの状態はここで管理する。
|
1248
1283
|
*/
|
1249
1284
|
/** @internal */
|
1250
1285
|
const handleState = (event) => {
|
@@ -1253,36 +1288,183 @@ const handleState = (event) => {
|
|
1253
1288
|
setState$1(event.detail.to, { disableInPreview: event.detail.disableInPreview });
|
1254
1289
|
}
|
1255
1290
|
};
|
1256
|
-
/**
|
1257
|
-
|
1258
|
-
|
1259
|
-
|
1260
|
-
|
1291
|
+
/**
|
1292
|
+
* アクションが表示 (show) された後にフックする関数
|
1293
|
+
*
|
1294
|
+
* @param fn - 呼び出されるフック関数
|
1295
|
+
*
|
1296
|
+
* @public
|
1297
|
+
*/
|
1298
|
+
function onShow(fn) {
|
1299
|
+
let { onShowHandlers } = getInternalHandlers();
|
1300
|
+
if (!onShowHandlers) {
|
1301
|
+
onShowHandlers = [];
|
1261
1302
|
}
|
1262
|
-
|
1263
|
-
|
1264
|
-
|
1265
|
-
};
|
1266
|
-
/** @internal */
|
1267
|
-
const finalize = () => {
|
1268
|
-
resetSetting();
|
1269
|
-
};
|
1303
|
+
onShowHandlers.push(fn);
|
1304
|
+
setInternalHandlers({ onShowHandlers });
|
1305
|
+
}
|
1270
1306
|
/**
|
1271
|
-
*
|
1307
|
+
* アクションがクローズ (close) される前にフックする関数
|
1272
1308
|
*
|
1273
|
-
* @param
|
1274
|
-
* @param options - {@link ActionOptions | オプション}
|
1309
|
+
* @param fn - 呼び出されるフック関数
|
1275
1310
|
*
|
1276
|
-
* @
|
1311
|
+
* @public
|
1312
|
+
*/
|
1313
|
+
function onClose(fn) {
|
1314
|
+
let { onCloseHandlers } = getInternalHandlers();
|
1315
|
+
if (!onCloseHandlers) {
|
1316
|
+
onCloseHandlers = [];
|
1317
|
+
}
|
1318
|
+
onCloseHandlers.push(fn);
|
1319
|
+
setInternalHandlers({ onCloseHandlers });
|
1320
|
+
}
|
1321
|
+
/**
|
1322
|
+
* アクションのステートが変更された (changeState) 後にフックする関数
|
1323
|
+
*
|
1324
|
+
* @param fn - 呼び出されるフック関数
|
1277
1325
|
*
|
1278
1326
|
* @public
|
1279
1327
|
*/
|
1280
|
-
function
|
1328
|
+
function onChangeState(fn) {
|
1329
|
+
let { onChangeStateHandlers } = getInternalHandlers();
|
1330
|
+
if (!onChangeStateHandlers) {
|
1331
|
+
onChangeStateHandlers = [];
|
1332
|
+
}
|
1333
|
+
onChangeStateHandlers.push(fn);
|
1334
|
+
setInternalHandlers({ onChangeStateHandlers });
|
1335
|
+
}
|
1336
|
+
/**
|
1337
|
+
* アクションを表示する
|
1338
|
+
*
|
1339
|
+
* @public
|
1340
|
+
*/
|
1341
|
+
function showAction() {
|
1342
|
+
const event = new CustomEvent(ACTION_SHOW_EVENT, { detail: { trigger: 'custom' } });
|
1343
|
+
window.dispatchEvent(event);
|
1344
|
+
}
|
1345
|
+
/**
|
1346
|
+
* アクションを閉じる
|
1347
|
+
*
|
1348
|
+
* @param trigger - 閉じた時のトリガー。デフォルト `'none'`
|
1349
|
+
*
|
1350
|
+
* @public
|
1351
|
+
*/
|
1352
|
+
function closeAction(trigger = 'none') {
|
1353
|
+
const event = new CustomEvent(ACTION_CLOSE_EVENT, { detail: { trigger } });
|
1354
|
+
window.dispatchEvent(event);
|
1355
|
+
}
|
1356
|
+
/**
|
1357
|
+
* アクションに CSS を適用する
|
1358
|
+
*
|
1359
|
+
* @param css - 適用する CSS
|
1360
|
+
*
|
1361
|
+
* @returns 適用された style 要素を返す Promise
|
1362
|
+
*
|
1363
|
+
* @public
|
1364
|
+
*/
|
1365
|
+
async function applyCss(css) {
|
1366
|
+
return new Promise((resolve, reject) => {
|
1367
|
+
const style = document.createElement('style');
|
1368
|
+
style.textContent = css;
|
1369
|
+
const shadowRoot = getActionRoot();
|
1370
|
+
if (!shadowRoot)
|
1371
|
+
return;
|
1372
|
+
shadowRoot.append(style);
|
1373
|
+
style.addEventListener('load', () => resolve(style));
|
1374
|
+
style.addEventListener('error', () => reject(style));
|
1375
|
+
});
|
1376
|
+
}
|
1377
|
+
async function fixFontFaceIssue(href, cssRules) {
|
1378
|
+
const css = new CSSStyleSheet();
|
1379
|
+
// @ts-ignore
|
1380
|
+
await css.replace(cssRules);
|
1381
|
+
const rules = [];
|
1382
|
+
const fixedRules = [];
|
1383
|
+
Array.from(css.cssRules).forEach(cssRule => {
|
1384
|
+
if (cssRule.type !== 5) {
|
1385
|
+
rules.push(cssRule.cssText);
|
1386
|
+
}
|
1387
|
+
// type 5 is @font-face
|
1388
|
+
const split = href.split('/');
|
1389
|
+
const stylePath = split.slice(0, split.length - 1).join('/');
|
1390
|
+
const cssText = cssRule.cssText;
|
1391
|
+
const newCssText = cssText.replace(
|
1392
|
+
// relative paths
|
1393
|
+
/url\s*\(\s*['"]?(?!((\/)|((?:https?:)?\/\/)|(?:data:?:)))([^'")]+)['"]?\s*\)/g, `url("${stylePath}/$4")`);
|
1394
|
+
if (cssText === newCssText)
|
1395
|
+
return;
|
1396
|
+
fixedRules.push(newCssText);
|
1397
|
+
});
|
1398
|
+
return [rules.join('\n'), fixedRules.join('\n')];
|
1399
|
+
}
|
1400
|
+
/**
|
1401
|
+
* アクションにグローバルなスタイルを読み込む
|
1402
|
+
*
|
1403
|
+
* @param href - style ファイルのリンク URL
|
1404
|
+
*
|
1405
|
+
* @public
|
1406
|
+
*/
|
1407
|
+
async function loadStyle(href) {
|
1408
|
+
const sr = getActionRoot();
|
1409
|
+
if (!sr)
|
1410
|
+
return;
|
1411
|
+
let cssRules = '';
|
1412
|
+
try {
|
1413
|
+
const res = await fetch(href);
|
1414
|
+
cssRules = await res.text();
|
1415
|
+
}
|
1416
|
+
catch (e) {
|
1417
|
+
// pass
|
1418
|
+
}
|
1419
|
+
if (!cssRules)
|
1420
|
+
return;
|
1421
|
+
// Chromeのバグで、Shadow Rootの@font-faceを絶対パスで指定する必要がある
|
1422
|
+
// @see https://stackoverflow.com/a/63717709
|
1423
|
+
const [rules, fontFaceRules] = await fixFontFaceIssue(href, cssRules);
|
1424
|
+
const css = new CSSStyleSheet();
|
1425
|
+
// @ts-ignore
|
1426
|
+
await css.replace(rules);
|
1427
|
+
const fontFaceCss = new CSSStyleSheet();
|
1428
|
+
// @ts-ignore
|
1429
|
+
await fontFaceCss.replace(fontFaceRules);
|
1430
|
+
// @ts-ignore
|
1431
|
+
sr.adoptedStyleSheets = [...sr.adoptedStyleSheets, css, fontFaceCss];
|
1432
|
+
// Chromeのバグで、ページとShadow Rootの両方に、@font-faceを設定する必要がある
|
1433
|
+
// @see https://stackoverflow.com/a/63717709
|
1434
|
+
// @ts-ignore
|
1435
|
+
document.adoptedStyleSheets = [...document.adoptedStyleSheets, css, fontFaceCss];
|
1436
|
+
}
|
1437
|
+
// @internal
|
1438
|
+
function getCssVariables(data) {
|
1439
|
+
return Object.entries(data)
|
1440
|
+
.filter(([key, value]) => {
|
1441
|
+
return ['string', 'number'].includes(typeof value) && key.startsWith('--');
|
1442
|
+
})
|
1443
|
+
.map(([key, value]) => `${key}:${value}`)
|
1444
|
+
.join(';');
|
1445
|
+
}
|
1446
|
+
/**
|
1447
|
+
* アクションのルートの DOM 要素を取得する
|
1448
|
+
*
|
1449
|
+
* @returns アクションがルートの DOM 要素 を持つ場合は DOM 要素を返します。ない場合は `null` を返します
|
1450
|
+
*
|
1451
|
+
* @public
|
1452
|
+
*/
|
1453
|
+
function getActionRoot() {
|
1454
|
+
const root = document.querySelector(`.${KARTE_ACTION_ROOT}[data-${KARTE_ACTION_RID}='${actionId}']`);
|
1455
|
+
if (!root?.shadowRoot) {
|
1456
|
+
return null;
|
1457
|
+
}
|
1458
|
+
return root.shadowRoot;
|
1459
|
+
}
|
1460
|
+
/** @internal */
|
1461
|
+
function createModal(App, options = {
|
1281
1462
|
send: () => { },
|
1282
1463
|
publish: () => { },
|
1283
1464
|
props: {},
|
1284
1465
|
variables: {},
|
1285
1466
|
localVariablesQuery: undefined,
|
1467
|
+
karteTemplate: {},
|
1286
1468
|
}) {
|
1287
1469
|
let app = null;
|
1288
1470
|
const data = {
|
@@ -1295,19 +1477,6 @@ function create(App, options = {
|
|
1295
1477
|
publish: options.publish,
|
1296
1478
|
data,
|
1297
1479
|
};
|
1298
|
-
const handleDestroy = () => {
|
1299
|
-
const { onDestroyHandlers } = getInternalHandlers();
|
1300
|
-
onDestroyHandlers?.forEach(h => {
|
1301
|
-
const actionHookLog = { name: 'onDestroy' };
|
1302
|
-
console.info(`${ACTION_HOOK_LABEL}:${JSON.stringify(actionHookLog)}`);
|
1303
|
-
h(actionProps);
|
1304
|
-
});
|
1305
|
-
// 旧Widget APIの内部で利用するため、実行ログは出力しない
|
1306
|
-
const { onDestroyHandlers: onDestroyWidgetHandlers } = getWidgetHandlers();
|
1307
|
-
if (onDestroyWidgetHandlers) {
|
1308
|
-
onDestroyWidgetHandlers.forEach(h => h(actionProps));
|
1309
|
-
}
|
1310
|
-
};
|
1311
1480
|
const close = (trigger = 'none') => {
|
1312
1481
|
if (!app) {
|
1313
1482
|
return NOOP;
|
@@ -1399,39 +1568,20 @@ function create(App, options = {
|
|
1399
1568
|
};
|
1400
1569
|
// ここからメインの処理
|
1401
1570
|
initialize({ send: options.send, initialState: data.initial_state });
|
1402
|
-
setSystem({
|
1403
|
-
// @ts-ignore
|
1404
|
-
apiKey: data.api_key || null,
|
1405
|
-
shortenId: data.shorten_id || null,
|
1406
|
-
campaignId: data.campaign_id || null,
|
1407
|
-
});
|
1408
1571
|
// ActionTable APIへの非同期リクエスト
|
1409
1572
|
let actionTablePromise = null;
|
1410
1573
|
if (options.localVariablesQuery && data.api_key) {
|
1411
|
-
actionTablePromise = (
|
1412
|
-
const result = await loadActionTable(options.localVariablesQuery, data.api_key);
|
1413
|
-
let success = false;
|
1414
|
-
if (Object.keys(result).length === options.localVariablesQuery.length) {
|
1415
|
-
setVariables(result);
|
1416
|
-
success = true;
|
1417
|
-
}
|
1418
|
-
return {
|
1419
|
-
success,
|
1420
|
-
};
|
1421
|
-
})();
|
1574
|
+
actionTablePromise = setupActionTable(options.localVariablesQuery, data.api_key);
|
1422
1575
|
}
|
1423
1576
|
// NOTE: onCreateより前にListenする必要がある
|
1424
1577
|
window.addEventListener(ACTION_SHOW_EVENT, handleShow);
|
1425
1578
|
window.addEventListener(ACTION_CLOSE_EVENT, handleClose);
|
1426
1579
|
window.addEventListener(ACTION_CHANGE_STATE_EVENT, handleState);
|
1427
|
-
window.addEventListener(ACTION_DESTROY_EVENT, handleDestroy);
|
1428
|
-
window.addEventListener('beforeunload', dispatchDestroyEvent, false);
|
1429
1580
|
let showTriggerCleanups = [];
|
1430
1581
|
let closeTriggerCleanups = [];
|
1431
1582
|
{
|
1432
1583
|
autoShow();
|
1433
1584
|
}
|
1434
|
-
const loggerCleanup = listenConsoleLogger() ;
|
1435
1585
|
// 旧Widget API IFの処理
|
1436
1586
|
const { onCreateHandlers } = getInternalHandlers();
|
1437
1587
|
if (onCreateHandlers) {
|
@@ -1440,7 +1590,6 @@ function create(App, options = {
|
|
1440
1590
|
console.debug(`${ACTION_HOOK_LABEL}: onCreate`);
|
1441
1591
|
});
|
1442
1592
|
}
|
1443
|
-
// カスタムスクリプトの処理
|
1444
1593
|
if (options.onCreate) {
|
1445
1594
|
options.onCreate(actionProps);
|
1446
1595
|
}
|
@@ -1452,9 +1601,6 @@ function create(App, options = {
|
|
1452
1601
|
window.removeEventListener(ACTION_SHOW_EVENT, handleShow);
|
1453
1602
|
window.removeEventListener(ACTION_CLOSE_EVENT, handleClose);
|
1454
1603
|
window.removeEventListener(ACTION_CHANGE_STATE_EVENT, handleState);
|
1455
|
-
window.removeEventListener(ACTION_DESTROY_EVENT, handleDestroy);
|
1456
|
-
window.removeEventListener('beforeunload', dispatchDestroyEvent, false);
|
1457
|
-
loggerCleanup();
|
1458
1604
|
};
|
1459
1605
|
return appCleanup;
|
1460
1606
|
}
|
@@ -1482,53 +1628,13 @@ function ensureActionRoot(useShadow = true) {
|
|
1482
1628
|
}
|
1483
1629
|
}
|
1484
1630
|
/**
|
1485
|
-
*
|
1486
|
-
*
|
1487
|
-
* @internal
|
1488
|
-
*/
|
1489
|
-
function dispatchDestroyEvent() {
|
1490
|
-
const event = new CustomEvent(ACTION_DESTROY_EVENT);
|
1491
|
-
window.dispatchEvent(event);
|
1492
|
-
}
|
1493
|
-
/**
|
1494
|
-
* アクションの破棄する
|
1495
|
-
*
|
1496
|
-
* @public
|
1497
|
-
*/
|
1498
|
-
function destroyAction() {
|
1499
|
-
setDestroyed(true);
|
1500
|
-
dispatchDestroyEvent();
|
1501
|
-
}
|
1502
|
-
/**
|
1503
|
-
* アクションが作成 (create) される前にフックする関数
|
1504
|
-
*
|
1505
|
-
* @param fn - 呼び出されるフック関数
|
1506
|
-
*
|
1507
|
-
* @public
|
1508
|
-
*/
|
1509
|
-
function onCreate(fn) {
|
1510
|
-
let { onCreateHandlers } = getInternalHandlers();
|
1511
|
-
if (!onCreateHandlers) {
|
1512
|
-
onCreateHandlers = [];
|
1513
|
-
}
|
1514
|
-
onCreateHandlers.push(fn);
|
1515
|
-
setInternalHandlers({ onCreateHandlers });
|
1516
|
-
}
|
1517
|
-
/**
|
1518
|
-
* アクションが破棄 (destroy) される前にフックする関数
|
1631
|
+
* 非推奨
|
1519
1632
|
*
|
1520
|
-
* @
|
1633
|
+
* @deprecated 非推奨
|
1521
1634
|
*
|
1522
|
-
* @
|
1635
|
+
* @internal
|
1523
1636
|
*/
|
1524
|
-
|
1525
|
-
let { onDestroyHandlers } = getInternalHandlers();
|
1526
|
-
if (!onDestroyHandlers) {
|
1527
|
-
onDestroyHandlers = [];
|
1528
|
-
}
|
1529
|
-
onDestroyHandlers.push(fn);
|
1530
|
-
setInternalHandlers({ onDestroyHandlers });
|
1531
|
-
}
|
1637
|
+
const show = showAction;
|
1532
1638
|
/**
|
1533
1639
|
* 非推奨
|
1534
1640
|
*
|
@@ -1536,7 +1642,7 @@ function onDestroy(fn) {
|
|
1536
1642
|
*
|
1537
1643
|
* @internal
|
1538
1644
|
*/
|
1539
|
-
const
|
1645
|
+
const close = closeAction;
|
1540
1646
|
/**
|
1541
1647
|
* 非推奨
|
1542
1648
|
*
|
@@ -1594,17 +1700,6 @@ function createApp(App, options = {
|
|
1594
1700
|
},
|
1595
1701
|
};
|
1596
1702
|
}
|
1597
|
-
/**
|
1598
|
-
* 非推奨
|
1599
|
-
*
|
1600
|
-
* @deprecated 非推奨
|
1601
|
-
*
|
1602
|
-
* @internal
|
1603
|
-
*/
|
1604
|
-
function destroy() {
|
1605
|
-
setDestroyed(true);
|
1606
|
-
dispatchDestroyEvent();
|
1607
|
-
}
|
1608
1703
|
/**
|
1609
1704
|
* 非推奨
|
1610
1705
|
*
|
@@ -1641,6 +1736,42 @@ function createFog({ color = '#000', opacity = '50%', zIndex = 999, onclick, })
|
|
1641
1736
|
/**
|
1642
1737
|
* スクリプト接客が利用するコードの管理
|
1643
1738
|
*/
|
1739
|
+
/** @internal */
|
1740
|
+
async function runScript$1(options = {
|
1741
|
+
send: () => { },
|
1742
|
+
publish: () => { },
|
1743
|
+
props: {},
|
1744
|
+
variables: {},
|
1745
|
+
localVariablesQuery: undefined,
|
1746
|
+
karteTemplate: {},
|
1747
|
+
}) {
|
1748
|
+
if (!options.onCreate)
|
1749
|
+
return;
|
1750
|
+
const data = {
|
1751
|
+
...options.props,
|
1752
|
+
...options.variables,
|
1753
|
+
...getVariables(),
|
1754
|
+
};
|
1755
|
+
const actionProps = {
|
1756
|
+
send: options.send,
|
1757
|
+
publish: options.publish,
|
1758
|
+
data,
|
1759
|
+
};
|
1760
|
+
initialize({ send: options.send, initialState: data.initial_state });
|
1761
|
+
const { success } = await setupActionTable(options.localVariablesQuery, data.api_key);
|
1762
|
+
if (!success)
|
1763
|
+
return;
|
1764
|
+
// 旧Widget API IFの処理
|
1765
|
+
const { onCreateHandlers } = getInternalHandlers();
|
1766
|
+
if (onCreateHandlers) {
|
1767
|
+
onCreateHandlers.forEach(h => {
|
1768
|
+
h({ send: options.send, publish: options.publish, data });
|
1769
|
+
console.debug(`${ACTION_HOOK_LABEL}: onCreate`);
|
1770
|
+
});
|
1771
|
+
}
|
1772
|
+
options.onCreate(actionProps);
|
1773
|
+
finalize();
|
1774
|
+
}
|
1644
1775
|
/**
|
1645
1776
|
* ES Modules に対応していない JavaScript をページに読み込む
|
1646
1777
|
*
|
@@ -1701,178 +1832,112 @@ async function loadGlobalStyle(href) {
|
|
1701
1832
|
}
|
1702
1833
|
|
1703
1834
|
/**
|
1704
|
-
*
|
1835
|
+
* Edgeが起動するアクションに関連するコードを管理する
|
1705
1836
|
*
|
1706
|
-
* アクションの
|
1837
|
+
* アクションのCreate, Destroyの状態はここで管理する。
|
1707
1838
|
*/
|
1708
1839
|
/**
|
1709
|
-
*
|
1710
|
-
*
|
1711
|
-
* @param fn - 呼び出されるフック関数
|
1840
|
+
* アクションを作成する
|
1712
1841
|
*
|
1713
|
-
* @
|
1714
|
-
|
1715
|
-
function onShow(fn) {
|
1716
|
-
let { onShowHandlers } = getInternalHandlers();
|
1717
|
-
if (!onShowHandlers) {
|
1718
|
-
onShowHandlers = [];
|
1719
|
-
}
|
1720
|
-
onShowHandlers.push(fn);
|
1721
|
-
setInternalHandlers({ onShowHandlers });
|
1722
|
-
}
|
1723
|
-
/**
|
1724
|
-
* アクションがクローズ (close) される前にフックする関数
|
1842
|
+
* @param App - Svelte コンポーネントのエントリポイント
|
1843
|
+
* @param options - {@link ActionOptions | オプション}
|
1725
1844
|
*
|
1726
|
-
* @
|
1845
|
+
* @returns アクションを破棄する関数
|
1727
1846
|
*
|
1728
1847
|
* @public
|
1729
1848
|
*/
|
1730
|
-
function
|
1731
|
-
|
1732
|
-
|
1733
|
-
|
1849
|
+
function create(App, options = {
|
1850
|
+
send: () => { },
|
1851
|
+
publish: () => { },
|
1852
|
+
props: {},
|
1853
|
+
variables: {},
|
1854
|
+
localVariablesQuery: undefined,
|
1855
|
+
karteTemplate: {},
|
1856
|
+
}) {
|
1857
|
+
const data = {
|
1858
|
+
...options.props,
|
1859
|
+
...options.variables,
|
1860
|
+
...getVariables(),
|
1861
|
+
};
|
1862
|
+
const actionProps = {
|
1863
|
+
send: options.send,
|
1864
|
+
publish: options.publish,
|
1865
|
+
data,
|
1866
|
+
};
|
1867
|
+
const handleDestroy = () => {
|
1868
|
+
const { onDestroyHandlers } = getInternalHandlers();
|
1869
|
+
onDestroyHandlers?.forEach(h => {
|
1870
|
+
const actionHookLog = { name: 'onDestroy' };
|
1871
|
+
console.info(`${ACTION_HOOK_LABEL}:${JSON.stringify(actionHookLog)}`);
|
1872
|
+
h(actionProps);
|
1873
|
+
});
|
1874
|
+
// 旧Widget APIの内部で利用するため、実行ログは出力しない
|
1875
|
+
const { onDestroyHandlers: onDestroyWidgetHandlers } = getWidgetHandlers();
|
1876
|
+
if (onDestroyWidgetHandlers) {
|
1877
|
+
onDestroyWidgetHandlers.forEach(h => h(actionProps));
|
1878
|
+
}
|
1879
|
+
};
|
1880
|
+
// ここからメインの処理
|
1881
|
+
setSystem({
|
1882
|
+
// @ts-ignore
|
1883
|
+
apiKey: data.api_key || null,
|
1884
|
+
shortenId: data.shorten_id || null,
|
1885
|
+
campaignId: data.campaign_id || null,
|
1886
|
+
});
|
1887
|
+
const loggerCleanup = listenConsoleLogger() ;
|
1888
|
+
window.addEventListener(ACTION_DESTROY_EVENT, handleDestroy);
|
1889
|
+
window.addEventListener('beforeunload', dispatchDestroyEvent, false);
|
1890
|
+
let modalCleanup = NOOP;
|
1891
|
+
if (options.karteTemplate?.template_type === 'script') {
|
1892
|
+
runScript$1(options);
|
1734
1893
|
}
|
1735
|
-
|
1736
|
-
|
1737
|
-
}
|
1738
|
-
/**
|
1739
|
-
* アクションのステートが変更された (changeState) 後にフックする関数
|
1740
|
-
*
|
1741
|
-
* @param fn - 呼び出されるフック関数
|
1742
|
-
*
|
1743
|
-
* @public
|
1744
|
-
*/
|
1745
|
-
function onChangeState(fn) {
|
1746
|
-
let { onChangeStateHandlers } = getInternalHandlers();
|
1747
|
-
if (!onChangeStateHandlers) {
|
1748
|
-
onChangeStateHandlers = [];
|
1894
|
+
else {
|
1895
|
+
modalCleanup = createModal(App, options);
|
1749
1896
|
}
|
1750
|
-
|
1751
|
-
|
1752
|
-
|
1753
|
-
|
1754
|
-
|
1755
|
-
*
|
1756
|
-
* @public
|
1757
|
-
*/
|
1758
|
-
function showAction() {
|
1759
|
-
const event = new CustomEvent(ACTION_SHOW_EVENT, { detail: { trigger: 'custom' } });
|
1760
|
-
window.dispatchEvent(event);
|
1761
|
-
}
|
1762
|
-
/**
|
1763
|
-
* アクションを閉じる
|
1764
|
-
*
|
1765
|
-
* @param trigger - 閉じた時のトリガー。デフォルト `'none'`
|
1766
|
-
*
|
1767
|
-
* @public
|
1768
|
-
*/
|
1769
|
-
function closeAction(trigger = 'none') {
|
1770
|
-
const event = new CustomEvent(ACTION_CLOSE_EVENT, { detail: { trigger } });
|
1771
|
-
window.dispatchEvent(event);
|
1897
|
+
return () => {
|
1898
|
+
loggerCleanup();
|
1899
|
+
modalCleanup();
|
1900
|
+
window.removeEventListener(ACTION_DESTROY_EVENT, handleDestroy);
|
1901
|
+
};
|
1772
1902
|
}
|
1773
1903
|
/**
|
1774
|
-
*
|
1775
|
-
*
|
1776
|
-
* @param css - 適用する CSS
|
1777
|
-
*
|
1778
|
-
* @returns 適用された style 要素を返す Promise
|
1904
|
+
* アクションの破棄する
|
1779
1905
|
*
|
1780
1906
|
* @public
|
1781
1907
|
*/
|
1782
|
-
|
1783
|
-
|
1784
|
-
|
1785
|
-
style.textContent = css;
|
1786
|
-
const shadowRoot = getActionRoot();
|
1787
|
-
if (!shadowRoot)
|
1788
|
-
return;
|
1789
|
-
shadowRoot.append(style);
|
1790
|
-
style.addEventListener('load', () => resolve(style));
|
1791
|
-
style.addEventListener('error', () => reject(style));
|
1792
|
-
});
|
1793
|
-
}
|
1794
|
-
async function fixFontFaceIssue(href, cssRules) {
|
1795
|
-
const css = new CSSStyleSheet();
|
1796
|
-
// @ts-ignore
|
1797
|
-
await css.replace(cssRules);
|
1798
|
-
const rules = [];
|
1799
|
-
const fixedRules = [];
|
1800
|
-
Array.from(css.cssRules).forEach(cssRule => {
|
1801
|
-
if (cssRule.type !== 5) {
|
1802
|
-
rules.push(cssRule.cssText);
|
1803
|
-
}
|
1804
|
-
// type 5 is @font-face
|
1805
|
-
const split = href.split('/');
|
1806
|
-
const stylePath = split.slice(0, split.length - 1).join('/');
|
1807
|
-
const cssText = cssRule.cssText;
|
1808
|
-
const newCssText = cssText.replace(
|
1809
|
-
// relative paths
|
1810
|
-
/url\s*\(\s*['"]?(?!((\/)|((?:https?:)?\/\/)|(?:data:?:)))([^'")]+)['"]?\s*\)/g, `url("${stylePath}/$4")`);
|
1811
|
-
if (cssText === newCssText)
|
1812
|
-
return;
|
1813
|
-
fixedRules.push(newCssText);
|
1814
|
-
});
|
1815
|
-
return [rules.join('\n'), fixedRules.join('\n')];
|
1908
|
+
function destroyAction() {
|
1909
|
+
setDestroyed(true);
|
1910
|
+
dispatchDestroyEvent();
|
1816
1911
|
}
|
1817
1912
|
/**
|
1818
|
-
*
|
1913
|
+
* アクションが作成 (create) される前にフックする関数
|
1819
1914
|
*
|
1820
|
-
* @param
|
1915
|
+
* @param fn - 呼び出されるフック関数
|
1821
1916
|
*
|
1822
1917
|
* @public
|
1823
1918
|
*/
|
1824
|
-
|
1825
|
-
|
1826
|
-
if (!
|
1827
|
-
|
1828
|
-
let cssRules = '';
|
1829
|
-
try {
|
1830
|
-
const res = await fetch(href);
|
1831
|
-
cssRules = await res.text();
|
1832
|
-
}
|
1833
|
-
catch (e) {
|
1834
|
-
// pass
|
1919
|
+
function onCreate(fn) {
|
1920
|
+
let { onCreateHandlers } = getInternalHandlers();
|
1921
|
+
if (!onCreateHandlers) {
|
1922
|
+
onCreateHandlers = [];
|
1835
1923
|
}
|
1836
|
-
|
1837
|
-
|
1838
|
-
// Chromeのバグで、Shadow Rootの@font-faceを絶対パスで指定する必要がある
|
1839
|
-
// @see https://stackoverflow.com/a/63717709
|
1840
|
-
const [rules, fontFaceRules] = await fixFontFaceIssue(href, cssRules);
|
1841
|
-
const css = new CSSStyleSheet();
|
1842
|
-
// @ts-ignore
|
1843
|
-
await css.replace(rules);
|
1844
|
-
const fontFaceCss = new CSSStyleSheet();
|
1845
|
-
// @ts-ignore
|
1846
|
-
await fontFaceCss.replace(fontFaceRules);
|
1847
|
-
// @ts-ignore
|
1848
|
-
sr.adoptedStyleSheets = [...sr.adoptedStyleSheets, css, fontFaceCss];
|
1849
|
-
// Chromeのバグで、ページとShadow Rootの両方に、@font-faceを設定する必要がある
|
1850
|
-
// @see https://stackoverflow.com/a/63717709
|
1851
|
-
// @ts-ignore
|
1852
|
-
document.adoptedStyleSheets = [...document.adoptedStyleSheets, css, fontFaceCss];
|
1853
|
-
}
|
1854
|
-
// @internal
|
1855
|
-
function getCssVariables(data) {
|
1856
|
-
return Object.entries(data)
|
1857
|
-
.filter(([key, value]) => {
|
1858
|
-
return ['string', 'number'].includes(typeof value) && key.startsWith('--');
|
1859
|
-
})
|
1860
|
-
.map(([key, value]) => `${key}:${value}`)
|
1861
|
-
.join(';');
|
1924
|
+
onCreateHandlers.push(fn);
|
1925
|
+
setInternalHandlers({ onCreateHandlers });
|
1862
1926
|
}
|
1863
1927
|
/**
|
1864
|
-
*
|
1928
|
+
* アクションが破棄 (destroy) される前にフックする関数
|
1865
1929
|
*
|
1866
|
-
* @
|
1930
|
+
* @param fn - 呼び出されるフック関数
|
1867
1931
|
*
|
1868
1932
|
* @public
|
1869
1933
|
*/
|
1870
|
-
function
|
1871
|
-
|
1872
|
-
if (!
|
1873
|
-
|
1934
|
+
function onDestroy(fn) {
|
1935
|
+
let { onDestroyHandlers } = getInternalHandlers();
|
1936
|
+
if (!onDestroyHandlers) {
|
1937
|
+
onDestroyHandlers = [];
|
1874
1938
|
}
|
1875
|
-
|
1939
|
+
onDestroyHandlers.push(fn);
|
1940
|
+
setInternalHandlers({ onDestroyHandlers });
|
1876
1941
|
}
|
1877
1942
|
// -------- The following codes are deprecated --------
|
1878
1943
|
/**
|
@@ -1882,7 +1947,7 @@ function getActionRoot() {
|
|
1882
1947
|
*
|
1883
1948
|
* @internal
|
1884
1949
|
*/
|
1885
|
-
const
|
1950
|
+
const showModal = create;
|
1886
1951
|
/**
|
1887
1952
|
* 非推奨
|
1888
1953
|
*
|
@@ -1890,7 +1955,10 @@ const show = showAction;
|
|
1890
1955
|
*
|
1891
1956
|
* @internal
|
1892
1957
|
*/
|
1893
|
-
|
1958
|
+
function destroy() {
|
1959
|
+
setDestroyed(true);
|
1960
|
+
dispatchDestroyEvent();
|
1961
|
+
}
|
1894
1962
|
|
1895
1963
|
/**
|
1896
1964
|
* エディタv1のWidget API 互換のインターフェース
|
@@ -2729,13 +2797,13 @@ function customAnimation(node, { transform, animationStyle, delay = 0, duration
|
|
2729
2797
|
}
|
2730
2798
|
}
|
2731
2799
|
|
2732
|
-
/* src/components/
|
2800
|
+
/* src/components/BackgroundOverlay.svelte generated by Svelte v3.53.1 */
|
2733
2801
|
|
2734
2802
|
function add_css$s(target) {
|
2735
2803
|
append_styles(target, "svelte-1d4fta", ".background.svelte-1d4fta{position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0, 0, 0, 0.3);z-index:2147483646}");
|
2736
2804
|
}
|
2737
2805
|
|
2738
|
-
// (9:0) {#if
|
2806
|
+
// (9:0) {#if backgroundOverlay}
|
2739
2807
|
function create_if_block$7(ctx) {
|
2740
2808
|
let div;
|
2741
2809
|
let mounted;
|
@@ -2773,7 +2841,7 @@ function create_if_block$7(ctx) {
|
|
2773
2841
|
|
2774
2842
|
function create_fragment$v(ctx) {
|
2775
2843
|
let if_block_anchor;
|
2776
|
-
let if_block = /*
|
2844
|
+
let if_block = /*backgroundOverlay*/ ctx[0] && create_if_block$7(ctx);
|
2777
2845
|
|
2778
2846
|
return {
|
2779
2847
|
c() {
|
@@ -2789,7 +2857,7 @@ function create_fragment$v(ctx) {
|
|
2789
2857
|
insert_hydration(target, if_block_anchor, anchor);
|
2790
2858
|
},
|
2791
2859
|
p(ctx, [dirty]) {
|
2792
|
-
if (/*
|
2860
|
+
if (/*backgroundOverlay*/ ctx[0]) {
|
2793
2861
|
if (if_block) {
|
2794
2862
|
if_block.p(ctx, dirty);
|
2795
2863
|
} else {
|
@@ -2812,21 +2880,21 @@ function create_fragment$v(ctx) {
|
|
2812
2880
|
}
|
2813
2881
|
|
2814
2882
|
function instance$v($$self, $$props, $$invalidate) {
|
2815
|
-
let {
|
2883
|
+
let { backgroundOverlay = false } = $$props;
|
2816
2884
|
const dispatch = createEventDispatcher();
|
2817
2885
|
const click_handler = () => dispatch('click');
|
2818
2886
|
|
2819
2887
|
$$self.$$set = $$props => {
|
2820
|
-
if ('
|
2888
|
+
if ('backgroundOverlay' in $$props) $$invalidate(0, backgroundOverlay = $$props.backgroundOverlay);
|
2821
2889
|
};
|
2822
2890
|
|
2823
|
-
return [
|
2891
|
+
return [backgroundOverlay, dispatch, click_handler];
|
2824
2892
|
}
|
2825
2893
|
|
2826
|
-
class
|
2894
|
+
class BackgroundOverlay extends SvelteComponent {
|
2827
2895
|
constructor(options) {
|
2828
2896
|
super();
|
2829
|
-
init(this, options, instance$v, create_fragment$v, safe_not_equal, {
|
2897
|
+
init(this, options, instance$v, create_fragment$v, safe_not_equal, { backgroundOverlay: 0 }, add_css$s);
|
2830
2898
|
}
|
2831
2899
|
}
|
2832
2900
|
|
@@ -3651,20 +3719,20 @@ function create_default_slot$6(ctx) {
|
|
3651
3719
|
}
|
3652
3720
|
|
3653
3721
|
function create_fragment$t(ctx) {
|
3654
|
-
let
|
3722
|
+
let backgroundoverlay;
|
3655
3723
|
let t;
|
3656
3724
|
let if_block_anchor;
|
3657
3725
|
let current;
|
3658
3726
|
let mounted;
|
3659
3727
|
let dispose;
|
3660
3728
|
|
3661
|
-
|
3729
|
+
backgroundoverlay = new BackgroundOverlay({
|
3662
3730
|
props: {
|
3663
|
-
|
3731
|
+
backgroundOverlay: /*backgroundOverlay*/ ctx[10]
|
3664
3732
|
}
|
3665
3733
|
});
|
3666
3734
|
|
3667
|
-
|
3735
|
+
backgroundoverlay.$on("click", function () {
|
3668
3736
|
if (is_function(/*backgroundClick*/ ctx[18])) /*backgroundClick*/ ctx[18].apply(this, arguments);
|
3669
3737
|
});
|
3670
3738
|
|
@@ -3672,19 +3740,19 @@ function create_fragment$t(ctx) {
|
|
3672
3740
|
|
3673
3741
|
return {
|
3674
3742
|
c() {
|
3675
|
-
create_component(
|
3743
|
+
create_component(backgroundoverlay.$$.fragment);
|
3676
3744
|
t = space();
|
3677
3745
|
if (if_block) if_block.c();
|
3678
3746
|
if_block_anchor = empty();
|
3679
3747
|
},
|
3680
3748
|
l(nodes) {
|
3681
|
-
claim_component(
|
3749
|
+
claim_component(backgroundoverlay.$$.fragment, nodes);
|
3682
3750
|
t = claim_space(nodes);
|
3683
3751
|
if (if_block) if_block.l(nodes);
|
3684
3752
|
if_block_anchor = empty();
|
3685
3753
|
},
|
3686
3754
|
m(target, anchor) {
|
3687
|
-
mount_component(
|
3755
|
+
mount_component(backgroundoverlay, target, anchor);
|
3688
3756
|
insert_hydration(target, t, anchor);
|
3689
3757
|
if (if_block) if_block.m(target, anchor);
|
3690
3758
|
insert_hydration(target, if_block_anchor, anchor);
|
@@ -3700,9 +3768,9 @@ function create_fragment$t(ctx) {
|
|
3700
3768
|
},
|
3701
3769
|
p(new_ctx, [dirty]) {
|
3702
3770
|
ctx = new_ctx;
|
3703
|
-
const
|
3704
|
-
if (dirty & /*
|
3705
|
-
|
3771
|
+
const backgroundoverlay_changes = {};
|
3772
|
+
if (dirty & /*backgroundOverlay*/ 1024) backgroundoverlay_changes.backgroundOverlay = /*backgroundOverlay*/ ctx[10];
|
3773
|
+
backgroundoverlay.$set(backgroundoverlay_changes);
|
3706
3774
|
|
3707
3775
|
if (/*visible*/ ctx[12]) {
|
3708
3776
|
if (if_block) {
|
@@ -3729,17 +3797,17 @@ function create_fragment$t(ctx) {
|
|
3729
3797
|
},
|
3730
3798
|
i(local) {
|
3731
3799
|
if (current) return;
|
3732
|
-
transition_in(
|
3800
|
+
transition_in(backgroundoverlay.$$.fragment, local);
|
3733
3801
|
transition_in(if_block);
|
3734
3802
|
current = true;
|
3735
3803
|
},
|
3736
3804
|
o(local) {
|
3737
|
-
transition_out(
|
3805
|
+
transition_out(backgroundoverlay.$$.fragment, local);
|
3738
3806
|
transition_out(if_block);
|
3739
3807
|
current = false;
|
3740
3808
|
},
|
3741
3809
|
d(detaching) {
|
3742
|
-
destroy_component(
|
3810
|
+
destroy_component(backgroundoverlay, detaching);
|
3743
3811
|
if (detaching) detach(t);
|
3744
3812
|
if (if_block) if_block.d(detaching);
|
3745
3813
|
if (detaching) detach(if_block_anchor);
|
@@ -3776,7 +3844,7 @@ function instance$t($$self, $$props, $$invalidate) {
|
|
3776
3844
|
let { closeEventValue = null } = $$props;
|
3777
3845
|
let { closeButtonColor = '#000000' } = $$props;
|
3778
3846
|
let { _closeStyle = '' } = $$props;
|
3779
|
-
let
|
3847
|
+
let backgroundOverlay = DefaultModalPlacement.backgroundOverlay;
|
3780
3848
|
let backgroundClickFunction = DefaultModalPlacement.backgroundClick;
|
3781
3849
|
let modal;
|
3782
3850
|
|
@@ -3827,7 +3895,7 @@ function instance$t($$self, $$props, $$invalidate) {
|
|
3827
3895
|
if ($$self.$$.dirty & /*placement*/ 2097152) {
|
3828
3896
|
{
|
3829
3897
|
{
|
3830
|
-
$$invalidate(10,
|
3898
|
+
$$invalidate(10, backgroundOverlay = false);
|
3831
3899
|
}
|
3832
3900
|
}
|
3833
3901
|
}
|
@@ -3902,7 +3970,7 @@ function instance$t($$self, $$props, $$invalidate) {
|
|
3902
3970
|
closeEventValue,
|
3903
3971
|
closeButtonColor,
|
3904
3972
|
_closeStyle,
|
3905
|
-
|
3973
|
+
backgroundOverlay,
|
3906
3974
|
modal,
|
3907
3975
|
visible,
|
3908
3976
|
handle_keydown,
|