@plaidev/karte-action-sdk 1.1.176-28039456.06c11c78 → 1.1.177-28039844.a230804c
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 +1245 -2266
- package/dist/hydrate/index.es.js +659 -641
- package/dist/index.es.d.ts +1245 -2266
- package/dist/index.es.js +687 -669
- package/package.json +1 -1
package/dist/index.es.js
CHANGED
@@ -1,8 +1,33 @@
|
|
1
|
-
import { linear, elasticOut, cubicOut } from 'svelte/easing';
|
2
1
|
import { writable, get } from 'svelte/store';
|
3
2
|
import { onMount as onMount$1, onDestroy as onDestroy$1, beforeUpdate as beforeUpdate$1, afterUpdate as afterUpdate$1, tick as tick$1, setContext, getContext, createEventDispatcher } from 'svelte';
|
4
3
|
import { SvelteComponent, init, safe_not_equal, create_slot, update_slot_base, get_all_dirty_from_scope, get_slot_changes, transition_in, transition_out, append_styles, empty, insert, group_outros, check_outros, detach, component_subscribe, element, space, attr, noop, listen, null_to_empty, is_function, create_component, mount_component, destroy_component, add_render_callback, create_in_transition, binding_callbacks, set_style, svg_element, append, destroy_each, text, set_data, src_url_equal, HtmlTag, construct_svelte_component, subscribe } from 'svelte/internal';
|
4
|
+
import { linear, elasticOut, cubicOut } from 'svelte/easing';
|
5
|
+
|
6
|
+
/** @internal */
|
7
|
+
const ACTION_HOOK_LABEL = '__ACTION_HOOK__';
|
8
|
+
/** @internal */
|
9
|
+
const KARTE_ACTION_ROOT = 'karte-action-root';
|
10
|
+
/** @internal */
|
11
|
+
const KARTE_ACTION_RID = 'karte-action-rid';
|
12
|
+
/** @internal */
|
13
|
+
const KARTE_ACTION_SHORTEN_ID = 'karte-action-id';
|
14
|
+
/** @internal */
|
15
|
+
const ALL_ACTION_ID = 'KARTE_ALL_ACTION_ID';
|
16
|
+
/** @internal */
|
17
|
+
const ALL_ACTION_SHORTEN_ID = 'KARTE_ALL_ACTION_SHORTEN_ID';
|
18
|
+
// -------- The following codes are deprecated --------
|
19
|
+
/**
|
20
|
+
* 非推奨
|
21
|
+
*
|
22
|
+
* @deprecated 非推奨
|
23
|
+
*
|
24
|
+
* @internal
|
25
|
+
*/
|
26
|
+
const KARTE_MODAL_ROOT = 'karte-modal-root';
|
5
27
|
|
28
|
+
/**
|
29
|
+
* 静的変数に関連するコードを管理する
|
30
|
+
*/
|
6
31
|
/** @internal */
|
7
32
|
const PropTypes = [
|
8
33
|
'BooleanKeyword',
|
@@ -247,6 +272,13 @@ const NOOP = (_args) => { }; // eslint-disable-line @typescript-eslint/no-unused
|
|
247
272
|
const isPreview = () => {
|
248
273
|
return false;
|
249
274
|
};
|
275
|
+
// prettier-ignore
|
276
|
+
/** @internal */
|
277
|
+
const actionId = typeof __FIX_ACTION_CHANGE_STATE_EVENT__ === 'string'
|
278
|
+
? __FIX_ACTION_CHANGE_STATE_EVENT__
|
279
|
+
: typeof __FLYER_GEN_ACTION_ID_ON_BUILD__ === 'string'
|
280
|
+
? __FLYER_GEN_ACTION_ID_ON_BUILD__
|
281
|
+
: randStr();
|
250
282
|
/** @internal */
|
251
283
|
const handleFocus = (node) => (e) => {
|
252
284
|
if (node) {
|
@@ -449,6 +481,23 @@ function randStr(digit = 8) {
|
|
449
481
|
function getGoogleFontsParam() {
|
450
482
|
return 'family=' + Fonts.map(font => font.replace(/ /g, '+')).join('&family=');
|
451
483
|
}
|
484
|
+
/** @internal */
|
485
|
+
const h = (type, props, ...children) => {
|
486
|
+
const el = document.createElement(type);
|
487
|
+
for (const key of Object.keys(props)) {
|
488
|
+
const v = props[key];
|
489
|
+
if (key === 'style') {
|
490
|
+
Object.assign(el.style, v);
|
491
|
+
}
|
492
|
+
else {
|
493
|
+
el.setAttribute(key, v);
|
494
|
+
}
|
495
|
+
}
|
496
|
+
for (const child of children) {
|
497
|
+
el.appendChild(child);
|
498
|
+
}
|
499
|
+
return el;
|
500
|
+
};
|
452
501
|
|
453
502
|
/**
|
454
503
|
* Store to handle action setting
|
@@ -809,446 +858,123 @@ function resetVariables() {
|
|
809
858
|
*/
|
810
859
|
const formData = writable({});
|
811
860
|
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
861
|
+
/**
|
862
|
+
* アクションのログの記録の管理
|
863
|
+
*/
|
864
|
+
const MESSAGES_LIMIT = 1000;
|
865
|
+
const EVENTS_LIMIT = 1000;
|
866
|
+
// 実行ログ
|
867
|
+
let logs = [];
|
868
|
+
// KARTEイベント
|
869
|
+
let events = [];
|
820
870
|
/** @internal */
|
821
|
-
function
|
822
|
-
|
823
|
-
subscribe(run) {
|
824
|
-
return formData.subscribe(formData => {
|
825
|
-
run(formData[name]?.value);
|
826
|
-
});
|
827
|
-
},
|
828
|
-
set(value) {
|
829
|
-
formData.update(prev => ({
|
830
|
-
...prev,
|
831
|
-
[name]: {
|
832
|
-
statePath,
|
833
|
-
value,
|
834
|
-
isValid: validator(value),
|
835
|
-
},
|
836
|
-
}));
|
837
|
-
},
|
838
|
-
update(updater) {
|
839
|
-
formData.update(prev => {
|
840
|
-
const prevValue = prev[name]?.value;
|
841
|
-
return {
|
842
|
-
...prev,
|
843
|
-
[name]: {
|
844
|
-
statePath,
|
845
|
-
value: updater(prevValue),
|
846
|
-
isValid: validator(prevValue),
|
847
|
-
},
|
848
|
-
};
|
849
|
-
});
|
850
|
-
},
|
851
|
-
};
|
852
|
-
if (isEmpty(get(writableValue))) {
|
853
|
-
writableValue.set(initialValue);
|
854
|
-
}
|
855
|
-
return writableValue;
|
871
|
+
function getLogs() {
|
872
|
+
return logs;
|
856
873
|
}
|
857
874
|
/** @internal */
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
|
875
|
+
function getEvents() {
|
876
|
+
return events;
|
877
|
+
}
|
878
|
+
// iframe内の場合は親windowを参照する
|
879
|
+
function w(w) {
|
880
|
+
return w.parent === w ? w : w.parent;
|
881
|
+
}
|
882
|
+
/**
|
883
|
+
* ログを送信する関数群
|
884
|
+
*
|
885
|
+
* @internal
|
886
|
+
*/
|
887
|
+
const logger = {
|
888
|
+
info: (...messages) => {
|
889
|
+
const log = cloneToJson({ level: 'info', messages, date: new Date() });
|
890
|
+
w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'log', log } }, '*');
|
866
891
|
},
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
892
|
+
log: (...messages) => {
|
893
|
+
const log = cloneToJson({ level: 'info', messages, date: new Date() });
|
894
|
+
w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'log', log } }, '*');
|
895
|
+
},
|
896
|
+
error: (...messages) => {
|
897
|
+
const log = cloneToJson({ level: 'error', messages, date: new Date() });
|
898
|
+
w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'log', log } }, '*');
|
899
|
+
},
|
900
|
+
warn: (...messages) => {
|
901
|
+
const log = cloneToJson({ level: 'warn', messages, date: new Date() });
|
902
|
+
w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'log', log } }, '*');
|
903
|
+
},
|
904
|
+
system: (...messages) => {
|
905
|
+
const log = cloneToJson({ level: 'system', messages, date: new Date() });
|
906
|
+
w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'log', log } }, '*');
|
907
|
+
},
|
908
|
+
event: (name, values) => {
|
909
|
+
const event = values ? { name, values, date: new Date() } : { name, date: new Date() };
|
910
|
+
w(window).postMessage({
|
911
|
+
type: 'KARTE-ACTION-LOGGER',
|
912
|
+
detail: { method: 'event', event, values: values },
|
913
|
+
}, '*');
|
914
|
+
},
|
915
|
+
clear: () => {
|
916
|
+
w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'clear' } }, '*');
|
917
|
+
},
|
918
|
+
clearEvents: () => {
|
919
|
+
w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'clearEvents' } }, '*');
|
920
|
+
},
|
921
|
+
};
|
922
|
+
/**
|
923
|
+
* メッセージを実行ログに表示する
|
924
|
+
*
|
925
|
+
* @internal
|
926
|
+
*/
|
927
|
+
function listenLogger() {
|
928
|
+
const handler = (event) => {
|
929
|
+
const { type, detail } = event.data;
|
930
|
+
if (event.origin !== location.origin) {
|
931
|
+
return;
|
879
932
|
}
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
|
933
|
+
if (type !== 'KARTE-ACTION-LOGGER') {
|
934
|
+
return;
|
935
|
+
}
|
936
|
+
if (detail.method === 'clear') {
|
937
|
+
logs = [];
|
938
|
+
}
|
939
|
+
else if (detail.method === 'clearEvents') {
|
940
|
+
events = [];
|
941
|
+
}
|
942
|
+
else if (detail.method === 'log') {
|
943
|
+
if (MESSAGES_LIMIT <= logs.length) {
|
944
|
+
logs.shift();
|
945
|
+
}
|
946
|
+
const { level, messages } = detail.log;
|
947
|
+
const log = { level, messages, date: new Date() };
|
948
|
+
logs.push(log);
|
949
|
+
}
|
950
|
+
else if (detail.method === 'event') {
|
951
|
+
if (EVENTS_LIMIT <= events.length) {
|
952
|
+
events.shift();
|
953
|
+
}
|
954
|
+
const { name, values } = detail.event;
|
955
|
+
const karteEvent = values
|
956
|
+
? { name, values, date: new Date() }
|
957
|
+
: { name, date: new Date() };
|
958
|
+
events.push(karteEvent);
|
884
959
|
}
|
885
|
-
}
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
...answersMap,
|
890
|
-
},
|
960
|
+
};
|
961
|
+
window.addEventListener('message', handler, false);
|
962
|
+
return () => {
|
963
|
+
window.removeEventListener('message', handler, false);
|
891
964
|
};
|
892
965
|
}
|
893
|
-
|
894
|
-
|
895
|
-
|
896
|
-
|
897
|
-
|
898
|
-
|
899
|
-
const values = formDataToEventValues(campaignId, formData$1);
|
900
|
-
return values;
|
901
|
-
}
|
902
|
-
return {};
|
903
|
-
}
|
904
|
-
|
905
|
-
/** @internal */
|
906
|
-
const ALL_ACTION_ID = 'KARTE_ALL_ACTION_ID';
|
907
|
-
/** @internal */
|
908
|
-
const ALL_ACTION_SHORTEN_ID = 'KARTE_ALL_ACTION_SHORTEN_ID';
|
909
|
-
// prettier-ignore
|
910
|
-
/** @internal */
|
911
|
-
const actionId = typeof __FIX_ACTION_CHANGE_STATE_EVENT__ === 'string'
|
912
|
-
? __FIX_ACTION_CHANGE_STATE_EVENT__
|
913
|
-
: typeof __FLYER_GEN_ACTION_ID_ON_BUILD__ === 'string'
|
914
|
-
? __FLYER_GEN_ACTION_ID_ON_BUILD__
|
915
|
-
: randStr();
|
916
|
-
/** @internal */
|
917
|
-
const ACTION_SHOW_EVENT = `KARTE-ACTION-SHOW-${actionId}`;
|
918
|
-
/** @internal */
|
919
|
-
const ACTION_CLOSE_EVENT = `KARTE-ACTION-CLOSE-${actionId}`;
|
920
|
-
/** @internal */
|
921
|
-
const ACTION_DESTROY_EVENT = `KARTE-ACTION-DESTROY-${actionId}`;
|
922
|
-
/** @internal */
|
923
|
-
const ACTION_CHANGE_STATE_EVENT = `KARTE-ACTION-CHANGE-STATE-${actionId}`;
|
924
|
-
/** @internal */
|
925
|
-
const handleState = (event) => {
|
926
|
-
if (event.detail.actionId === actionId || event.detail.actionId === ALL_ACTION_ID) {
|
927
|
-
send_event('_message_state_changed', { state: event.detail.to });
|
928
|
-
setState$1(event.detail.to, { disableInPreview: event.detail.disableInPreview });
|
929
|
-
}
|
930
|
-
};
|
931
|
-
/** @internal */
|
932
|
-
const initialize = (setting) => {
|
933
|
-
const newSetting = setSetting(setting);
|
934
|
-
if (newSetting.initialState) {
|
935
|
-
setState$1(newSetting.initialState);
|
936
|
-
}
|
937
|
-
setOpened(true);
|
938
|
-
setClosed(false); // deprecated
|
939
|
-
return () => finalize();
|
940
|
-
};
|
941
|
-
/** @internal */
|
942
|
-
const finalize = () => {
|
943
|
-
resetSetting();
|
944
|
-
};
|
945
|
-
/** @internal */
|
946
|
-
const send_event = (event_name, values) => {
|
947
|
-
const setting = getSetting();
|
948
|
-
setting?.send?.(event_name, values);
|
949
|
-
};
|
950
|
-
function _moveTo(to) {
|
951
|
-
window.dispatchEvent(new CustomEvent(ACTION_CHANGE_STATE_EVENT, { detail: { to, actionId } }));
|
952
|
-
}
|
953
|
-
/** @internal */
|
954
|
-
const moveTo = (to) => () => {
|
955
|
-
_moveTo(to);
|
956
|
-
};
|
957
|
-
/** @internal */
|
958
|
-
const linkTo = (to, targetBlank = true) => () => {
|
959
|
-
send_event('message_click', { url: to, state: getState$1() });
|
960
|
-
if (targetBlank) {
|
961
|
-
window.open(to);
|
962
|
-
}
|
963
|
-
else {
|
964
|
-
location.href = to;
|
965
|
-
}
|
966
|
-
};
|
967
|
-
/** @internal */
|
968
|
-
const closeApp = (trigger) => () => {
|
969
|
-
window.dispatchEvent(new CustomEvent(ACTION_CLOSE_EVENT, { detail: { trigger } }));
|
970
|
-
};
|
971
|
-
/** @internal */
|
972
|
-
const runScript = (handlerName) => () => {
|
973
|
-
const handlers = getEventHandlers();
|
974
|
-
const handler = handlers[handlerName];
|
975
|
-
if (!handler)
|
976
|
-
return;
|
977
|
-
try {
|
978
|
-
handler();
|
979
|
-
}
|
980
|
-
catch (e) {
|
981
|
-
console.warn('Failed to run custom handler', handlerName, e);
|
982
|
-
}
|
983
|
-
};
|
984
|
-
/** @internal */
|
985
|
-
const submitForm = (to) => () => {
|
986
|
-
const values = submit();
|
987
|
-
send_event('_answer_question', values);
|
988
|
-
_moveTo(to);
|
989
|
-
};
|
990
|
-
/** @internal */
|
991
|
-
const execOnClickOperation = (onClickOperation) => {
|
992
|
-
if (onClickOperation.operation === 'linkTo') {
|
993
|
-
linkTo(...onClickOperation.args)();
|
994
|
-
}
|
995
|
-
else if (onClickOperation.operation === 'moveTo') {
|
996
|
-
moveTo(...onClickOperation.args)();
|
997
|
-
}
|
998
|
-
else if (onClickOperation.operation === 'closeApp') {
|
999
|
-
closeApp(onClickOperation.args[0] || 'button')();
|
1000
|
-
}
|
1001
|
-
else if (onClickOperation.operation === 'runScript') {
|
1002
|
-
runScript(onClickOperation.args[0])();
|
1003
|
-
}
|
1004
|
-
else if (onClickOperation.operation === 'submitForm') {
|
1005
|
-
submitForm(onClickOperation.args[0])();
|
1006
|
-
}
|
1007
|
-
};
|
1008
|
-
/** @internal */
|
1009
|
-
const haveFunction = (onClickOperation) => {
|
1010
|
-
return onClickOperation.operation !== 'none';
|
1011
|
-
};
|
1012
|
-
function getAnimation(animation) {
|
1013
|
-
switch (animation.type) {
|
1014
|
-
case 'fade':
|
1015
|
-
return `opacity: ${animation.progress}`;
|
1016
|
-
case 'bounce': {
|
1017
|
-
const translateX = animation.x;
|
1018
|
-
const translateY = animation.y;
|
1019
|
-
return `transform: translate3d(${translateX}%, ${translateY}%, 0) scale(${animation.progress});`;
|
1020
|
-
}
|
1021
|
-
case 'slide-down': {
|
1022
|
-
const translateX = animation.x;
|
1023
|
-
const translateY = animation.y - 100 * (1 - animation.progress);
|
1024
|
-
return `transform: translate3d(${translateX}%, ${translateY}%, 0);`;
|
1025
|
-
}
|
1026
|
-
case 'slide-up': {
|
1027
|
-
const translateX = animation.x;
|
1028
|
-
const translateY = animation.y + 100 * (1 - animation.progress);
|
1029
|
-
return `transform: translate3d(${translateX}%, ${translateY}%, 0);`;
|
1030
|
-
}
|
1031
|
-
case 'slide-left': {
|
1032
|
-
const translateX = animation.x + 100 * (1 - animation.progress);
|
1033
|
-
const translateY = animation.y;
|
1034
|
-
return `transform: translate3d(${translateX}%, ${translateY}%, 0);`;
|
1035
|
-
}
|
1036
|
-
case 'slide-right': {
|
1037
|
-
const translateX = animation.x - 100 * (1 - animation.progress);
|
1038
|
-
const translateY = animation.y;
|
1039
|
-
return `transform: translate3d(${translateX}%, ${translateY}%, 0);`;
|
1040
|
-
}
|
1041
|
-
case 'none': {
|
1042
|
-
const translateX = animation.x;
|
1043
|
-
const translateY = animation.y;
|
1044
|
-
return `transform: translate3d(${translateX}%, ${translateY}%, 0);`;
|
1045
|
-
}
|
1046
|
-
default:
|
1047
|
-
console.warn(`[action-sdk] invalid '${animation}', so we use 'transform: none' instead`);
|
1048
|
-
return 'transform: none';
|
1049
|
-
}
|
1050
|
-
}
|
1051
|
-
const EASING = {
|
1052
|
-
fade: linear,
|
1053
|
-
bounce: elasticOut,
|
1054
|
-
'slide-down': cubicOut,
|
1055
|
-
'slide-up': cubicOut,
|
1056
|
-
'slide-left': cubicOut,
|
1057
|
-
'slide-right': cubicOut,
|
1058
|
-
none: linear,
|
1059
|
-
};
|
1060
|
-
/**
|
1061
|
-
* The function to activate svelte animation.
|
1062
|
-
*
|
1063
|
-
* @param node - A target node of animation. This argument is passed by svelte, by default.
|
1064
|
-
* @param customAnimationOptions - A custom animation option object
|
1065
|
-
*
|
1066
|
-
* @see {@link https://svelte.dev/docs#template-syntax-element-directives-transition-fn-custom-transition-functions| Custom transition functions} for detail documentation
|
1067
|
-
*
|
1068
|
-
* @internal
|
1069
|
-
*/
|
1070
|
-
function customAnimation(node, { transform, animationStyle, delay = 0, duration = 1000 }) {
|
1071
|
-
const [x, y] = transform;
|
1072
|
-
return {
|
1073
|
-
delay,
|
1074
|
-
duration,
|
1075
|
-
easing: EASING[animationStyle],
|
1076
|
-
css: (progress) => getAnimation({ type: animationStyle, x, y, progress }),
|
1077
|
-
};
|
1078
|
-
}
|
1079
|
-
/**
|
1080
|
-
* ES Modules に対応していない JavaScript をページに読み込む
|
1081
|
-
*
|
1082
|
-
* @param src - JavaScript ファイルのリンク URL
|
1083
|
-
*
|
1084
|
-
* @public
|
1085
|
-
*/
|
1086
|
-
async function loadGlobalScript(src) {
|
1087
|
-
return new Promise((resolve, reject) => {
|
1088
|
-
const script = document.createElement('script');
|
1089
|
-
script.src = src;
|
1090
|
-
document.body.appendChild(script);
|
1091
|
-
script.addEventListener('load', () => resolve(script));
|
1092
|
-
script.addEventListener('error', () => reject(script));
|
1093
|
-
});
|
1094
|
-
}
|
1095
|
-
/**
|
1096
|
-
* グローバル CSS をページに適用する
|
1097
|
-
*
|
1098
|
-
* @param css - CSS
|
1099
|
-
*
|
1100
|
-
* @public
|
1101
|
-
*/
|
1102
|
-
async function applyGlobalCss(css) {
|
1103
|
-
return new Promise((resolve, reject) => {
|
1104
|
-
const style = document.createElement('style');
|
1105
|
-
style.textContent = css;
|
1106
|
-
document.body.appendChild(style);
|
1107
|
-
style.addEventListener('load', () => resolve(style));
|
1108
|
-
style.addEventListener('error', () => reject(style));
|
1109
|
-
});
|
1110
|
-
}
|
1111
|
-
/**
|
1112
|
-
* style ファイルをページに読み込む
|
1113
|
-
*
|
1114
|
-
* @param href - style ファイルのリンク URL
|
1115
|
-
*
|
1116
|
-
* @public
|
1117
|
-
*/
|
1118
|
-
async function loadGlobalStyle(href) {
|
1119
|
-
return new Promise((resolve, reject) => {
|
1120
|
-
const link = document.createElement('link');
|
1121
|
-
link.rel = 'stylesheet';
|
1122
|
-
link.href = href;
|
1123
|
-
document.body.appendChild(link);
|
1124
|
-
link.addEventListener('load', () => resolve(link));
|
1125
|
-
link.addEventListener('error', () => reject(link));
|
1126
|
-
});
|
1127
|
-
}
|
1128
|
-
// @internal
|
1129
|
-
function getCssVariables(data) {
|
1130
|
-
return Object.entries(data)
|
1131
|
-
.filter(([key, value]) => {
|
1132
|
-
return ['string', 'number'].includes(typeof value) && key.startsWith('--');
|
1133
|
-
})
|
1134
|
-
.map(([key, value]) => `${key}:${value}`)
|
1135
|
-
.join(';');
|
1136
|
-
}
|
1137
|
-
|
1138
|
-
/**
|
1139
|
-
* アクションのログの記録の管理
|
1140
|
-
*/
|
1141
|
-
const MESSAGES_LIMIT = 1000;
|
1142
|
-
const EVENTS_LIMIT = 1000;
|
1143
|
-
// 実行ログ
|
1144
|
-
let logs = [];
|
1145
|
-
// KARTEイベント
|
1146
|
-
let events = [];
|
1147
|
-
/** @internal */
|
1148
|
-
function getLogs() {
|
1149
|
-
return logs;
|
1150
|
-
}
|
1151
|
-
/** @internal */
|
1152
|
-
function getEvents() {
|
1153
|
-
return events;
|
1154
|
-
}
|
1155
|
-
// iframe内の場合は親windowを参照する
|
1156
|
-
function w(w) {
|
1157
|
-
return w.parent === w ? w : w.parent;
|
1158
|
-
}
|
1159
|
-
/**
|
1160
|
-
* ログを送信する関数群
|
1161
|
-
*
|
1162
|
-
* @internal
|
1163
|
-
*/
|
1164
|
-
const logger = {
|
1165
|
-
info: (...messages) => {
|
1166
|
-
const log = cloneToJson({ level: 'info', messages, date: new Date() });
|
1167
|
-
w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'log', log } }, '*');
|
1168
|
-
},
|
1169
|
-
log: (...messages) => {
|
1170
|
-
const log = cloneToJson({ level: 'info', messages, date: new Date() });
|
1171
|
-
w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'log', log } }, '*');
|
1172
|
-
},
|
1173
|
-
error: (...messages) => {
|
1174
|
-
const log = cloneToJson({ level: 'error', messages, date: new Date() });
|
1175
|
-
w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'log', log } }, '*');
|
1176
|
-
},
|
1177
|
-
warn: (...messages) => {
|
1178
|
-
const log = cloneToJson({ level: 'warn', messages, date: new Date() });
|
1179
|
-
w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'log', log } }, '*');
|
1180
|
-
},
|
1181
|
-
system: (...messages) => {
|
1182
|
-
const log = cloneToJson({ level: 'system', messages, date: new Date() });
|
1183
|
-
w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'log', log } }, '*');
|
1184
|
-
},
|
1185
|
-
event: (name, values) => {
|
1186
|
-
const event = values ? { name, values, date: new Date() } : { name, date: new Date() };
|
1187
|
-
w(window).postMessage({
|
1188
|
-
type: 'KARTE-ACTION-LOGGER',
|
1189
|
-
detail: { method: 'event', event, values: values },
|
1190
|
-
}, '*');
|
1191
|
-
},
|
1192
|
-
clear: () => {
|
1193
|
-
w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'clear' } }, '*');
|
1194
|
-
},
|
1195
|
-
clearEvents: () => {
|
1196
|
-
w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'clearEvents' } }, '*');
|
1197
|
-
},
|
1198
|
-
};
|
1199
|
-
/**
|
1200
|
-
* メッセージを実行ログに表示する
|
1201
|
-
*
|
1202
|
-
* @internal
|
1203
|
-
*/
|
1204
|
-
function listenLogger() {
|
1205
|
-
const handler = (event) => {
|
1206
|
-
const { type, detail } = event.data;
|
1207
|
-
if (event.origin !== location.origin) {
|
1208
|
-
return;
|
1209
|
-
}
|
1210
|
-
if (type !== 'KARTE-ACTION-LOGGER') {
|
1211
|
-
return;
|
1212
|
-
}
|
1213
|
-
if (detail.method === 'clear') {
|
1214
|
-
logs = [];
|
1215
|
-
}
|
1216
|
-
else if (detail.method === 'clearEvents') {
|
1217
|
-
events = [];
|
1218
|
-
}
|
1219
|
-
else if (detail.method === 'log') {
|
1220
|
-
if (MESSAGES_LIMIT <= logs.length) {
|
1221
|
-
logs.shift();
|
1222
|
-
}
|
1223
|
-
const { level, messages } = detail.log;
|
1224
|
-
const log = { level, messages, date: new Date() };
|
1225
|
-
logs.push(log);
|
1226
|
-
}
|
1227
|
-
else if (detail.method === 'event') {
|
1228
|
-
if (EVENTS_LIMIT <= events.length) {
|
1229
|
-
events.shift();
|
1230
|
-
}
|
1231
|
-
const { name, values } = detail.event;
|
1232
|
-
const karteEvent = values
|
1233
|
-
? { name, values, date: new Date() }
|
1234
|
-
: { name, date: new Date() };
|
1235
|
-
events.push(karteEvent);
|
1236
|
-
}
|
1237
|
-
};
|
1238
|
-
window.addEventListener('message', handler, false);
|
1239
|
-
return () => {
|
1240
|
-
window.removeEventListener('message', handler, false);
|
1241
|
-
};
|
1242
|
-
}
|
1243
|
-
function cloneToJson(data) {
|
1244
|
-
try {
|
1245
|
-
return JSON.parse(JSON.stringify(data));
|
1246
|
-
}
|
1247
|
-
catch (e) {
|
1248
|
-
return data;
|
966
|
+
function cloneToJson(data) {
|
967
|
+
try {
|
968
|
+
return JSON.parse(JSON.stringify(data));
|
969
|
+
}
|
970
|
+
catch (e) {
|
971
|
+
return data;
|
1249
972
|
}
|
1250
973
|
}
|
1251
974
|
|
975
|
+
/**
|
976
|
+
* モーダル(ポップアップ)のロジックを管理する
|
977
|
+
*/
|
1252
978
|
function doPresent({ direction, deltaRate }, downFn, upFn, condition = false) {
|
1253
979
|
if (direction === 'down' && deltaRate > 0) {
|
1254
980
|
downFn();
|
@@ -1393,6 +1119,23 @@ function checkAndDo(checkFn, fn, ...conditionFns) {
|
|
1393
1119
|
return haveCondition ? cleanupAll : null;
|
1394
1120
|
}
|
1395
1121
|
|
1122
|
+
/** @internal */
|
1123
|
+
const ACTION_DESTROY_EVENT = `KARTE-ACTION-DESTROY-${actionId}`;
|
1124
|
+
/** @internal */
|
1125
|
+
const ACTION_SHOW_EVENT = `KARTE-ACTION-SHOW-${actionId}`;
|
1126
|
+
/** @internal */
|
1127
|
+
const ACTION_CLOSE_EVENT = `KARTE-ACTION-CLOSE-${actionId}`;
|
1128
|
+
/** @internal */
|
1129
|
+
const ACTION_CHANGE_STATE_EVENT = `KARTE-ACTION-CHANGE-STATE-${actionId}`;
|
1130
|
+
/** @internal */
|
1131
|
+
const send_event = (event_name, values) => {
|
1132
|
+
const setting = getSetting();
|
1133
|
+
setting?.send?.(event_name, values);
|
1134
|
+
};
|
1135
|
+
|
1136
|
+
/**
|
1137
|
+
* アクションテーブルに関連するコードの管理
|
1138
|
+
*/
|
1396
1139
|
const DEFAULT_COLLECTION_ENDPOINT = typeof __FLYER_GEN_COLLECTION_API_ENDPOINT__ === 'string'
|
1397
1140
|
? __FLYER_GEN_COLLECTION_API_ENDPOINT__
|
1398
1141
|
: 'https://t.karte.io/collection';
|
@@ -1498,83 +1241,34 @@ const loadActionTable = async (config, api_key, endpoint) => {
|
|
1498
1241
|
}, {});
|
1499
1242
|
};
|
1500
1243
|
|
1501
|
-
/** @internal */
|
1502
|
-
const ACTION_HOOK_LABEL = '__ACTION_HOOK__';
|
1503
|
-
/**
|
1504
|
-
* アクションが作成 (create) される前にフックする関数
|
1505
|
-
*
|
1506
|
-
* @param fn - 呼び出されるフック関数
|
1507
|
-
*
|
1508
|
-
* @public
|
1509
|
-
*/
|
1510
|
-
function onCreate(fn) {
|
1511
|
-
let { onCreateHandlers } = getInternalHandlers();
|
1512
|
-
if (!onCreateHandlers) {
|
1513
|
-
onCreateHandlers = [];
|
1514
|
-
}
|
1515
|
-
onCreateHandlers.push(fn);
|
1516
|
-
setInternalHandlers({ onCreateHandlers });
|
1517
|
-
}
|
1518
|
-
/**
|
1519
|
-
* アクションが表示 (show) された後にフックする関数
|
1520
|
-
*
|
1521
|
-
* @param fn - 呼び出されるフック関数
|
1522
|
-
*
|
1523
|
-
* @public
|
1524
|
-
*/
|
1525
|
-
function onShow(fn) {
|
1526
|
-
let { onShowHandlers } = getInternalHandlers();
|
1527
|
-
if (!onShowHandlers) {
|
1528
|
-
onShowHandlers = [];
|
1529
|
-
}
|
1530
|
-
onShowHandlers.push(fn);
|
1531
|
-
setInternalHandlers({ onShowHandlers });
|
1532
|
-
}
|
1533
|
-
/**
|
1534
|
-
* アクションがクローズ (close) される前にフックする関数
|
1535
|
-
*
|
1536
|
-
* @param fn - 呼び出されるフック関数
|
1537
|
-
*
|
1538
|
-
* @public
|
1539
|
-
*/
|
1540
|
-
function onClose(fn) {
|
1541
|
-
let { onCloseHandlers } = getInternalHandlers();
|
1542
|
-
if (!onCloseHandlers) {
|
1543
|
-
onCloseHandlers = [];
|
1544
|
-
}
|
1545
|
-
onCloseHandlers.push(fn);
|
1546
|
-
setInternalHandlers({ onCloseHandlers });
|
1547
|
-
}
|
1548
1244
|
/**
|
1549
|
-
*
|
1245
|
+
* Edgeが起動するアクションに関連するコードを管理する
|
1550
1246
|
*
|
1551
|
-
*
|
1247
|
+
* アクションのCreate, Destroyの状態はここで管理する。
|
1552
1248
|
*
|
1553
|
-
*
|
1249
|
+
* FIXME: モーダルなどの機能ごとのコードを分離したい
|
1554
1250
|
*/
|
1555
|
-
|
1556
|
-
|
1557
|
-
if (
|
1558
|
-
|
1251
|
+
/** @internal */
|
1252
|
+
const handleState = (event) => {
|
1253
|
+
if (event.detail.actionId === actionId || event.detail.actionId === ALL_ACTION_ID) {
|
1254
|
+
send_event('_message_state_changed', { state: event.detail.to });
|
1255
|
+
setState$1(event.detail.to, { disableInPreview: event.detail.disableInPreview });
|
1559
1256
|
}
|
1560
|
-
|
1561
|
-
|
1562
|
-
|
1563
|
-
|
1564
|
-
|
1565
|
-
|
1566
|
-
* @param fn - 呼び出されるフック関数
|
1567
|
-
*
|
1568
|
-
* @public
|
1569
|
-
*/
|
1570
|
-
function onChangeState(fn) {
|
1571
|
-
let { onChangeStateHandlers } = getInternalHandlers();
|
1572
|
-
if (!onChangeStateHandlers) {
|
1573
|
-
onChangeStateHandlers = [];
|
1257
|
+
};
|
1258
|
+
/** @internal */
|
1259
|
+
const initialize = (setting) => {
|
1260
|
+
const newSetting = setSetting(setting);
|
1261
|
+
if (newSetting.initialState) {
|
1262
|
+
setState$1(newSetting.initialState);
|
1574
1263
|
}
|
1575
|
-
|
1576
|
-
|
1577
|
-
|
1264
|
+
setOpened(true);
|
1265
|
+
setClosed(false); // deprecated
|
1266
|
+
return () => finalize();
|
1267
|
+
};
|
1268
|
+
/** @internal */
|
1269
|
+
const finalize = () => {
|
1270
|
+
resetSetting();
|
1271
|
+
};
|
1578
1272
|
/**
|
1579
1273
|
* アクションを作成する
|
1580
1274
|
*
|
@@ -1791,6 +1485,29 @@ function create(App, options = {
|
|
1791
1485
|
};
|
1792
1486
|
return appCleanup;
|
1793
1487
|
}
|
1488
|
+
/** @internal */
|
1489
|
+
function ensureActionRoot(useShadow = true) {
|
1490
|
+
const systemConfig = getSystem();
|
1491
|
+
const rootAttrs = {
|
1492
|
+
class: `${KARTE_ACTION_ROOT} ${KARTE_MODAL_ROOT}`,
|
1493
|
+
[`data-${KARTE_ACTION_RID}`]: actionId,
|
1494
|
+
[`data-${KARTE_ACTION_SHORTEN_ID}`]: systemConfig.shortenId
|
1495
|
+
? systemConfig.shortenId
|
1496
|
+
: ALL_ACTION_SHORTEN_ID,
|
1497
|
+
};
|
1498
|
+
let el = document.querySelector(`.${KARTE_MODAL_ROOT}[data-${KARTE_ACTION_RID}='${actionId}']`);
|
1499
|
+
if (el == null) {
|
1500
|
+
el = h('div', rootAttrs);
|
1501
|
+
document.body.appendChild(el);
|
1502
|
+
}
|
1503
|
+
const isShadow = !!document.body.attachShadow && useShadow;
|
1504
|
+
if (isShadow) {
|
1505
|
+
return el.shadowRoot ?? el.attachShadow({ mode: 'open' });
|
1506
|
+
}
|
1507
|
+
else {
|
1508
|
+
return el;
|
1509
|
+
}
|
1510
|
+
}
|
1794
1511
|
/**
|
1795
1512
|
* Dispatch the event to destroy KARTE action
|
1796
1513
|
*
|
@@ -1810,71 +1527,110 @@ function destroyAction() {
|
|
1810
1527
|
dispatchDestroyEvent();
|
1811
1528
|
}
|
1812
1529
|
/**
|
1813
|
-
*
|
1530
|
+
* アクションが作成 (create) される前にフックする関数
|
1531
|
+
*
|
1532
|
+
* @param fn - 呼び出されるフック関数
|
1814
1533
|
*
|
1815
1534
|
* @public
|
1816
1535
|
*/
|
1817
|
-
function
|
1818
|
-
|
1819
|
-
|
1536
|
+
function onCreate(fn) {
|
1537
|
+
let { onCreateHandlers } = getInternalHandlers();
|
1538
|
+
if (!onCreateHandlers) {
|
1539
|
+
onCreateHandlers = [];
|
1540
|
+
}
|
1541
|
+
onCreateHandlers.push(fn);
|
1542
|
+
setInternalHandlers({ onCreateHandlers });
|
1820
1543
|
}
|
1821
1544
|
/**
|
1822
|
-
*
|
1545
|
+
* アクションが破棄 (destroy) される前にフックする関数
|
1823
1546
|
*
|
1824
|
-
* @param
|
1547
|
+
* @param fn - 呼び出されるフック関数
|
1825
1548
|
*
|
1826
1549
|
* @public
|
1827
1550
|
*/
|
1828
|
-
function
|
1829
|
-
|
1830
|
-
|
1831
|
-
|
1832
|
-
/** @internal */
|
1833
|
-
const KARTE_ACTION_ROOT = 'karte-action-root';
|
1834
|
-
/** @internal */
|
1835
|
-
const KARTE_ACTION_RID = 'karte-action-rid';
|
1836
|
-
/** @internal */
|
1837
|
-
const KARTE_ACTION_SHORTEN_ID = 'karte-action-id';
|
1838
|
-
/** @internal */
|
1839
|
-
function ensureActionRoot(useShadow = true) {
|
1840
|
-
const systemConfig = getSystem();
|
1841
|
-
const rootAttrs = {
|
1842
|
-
class: `${KARTE_ACTION_ROOT} ${KARTE_MODAL_ROOT}`,
|
1843
|
-
[`data-${KARTE_ACTION_RID}`]: actionId,
|
1844
|
-
[`data-${KARTE_ACTION_SHORTEN_ID}`]: systemConfig.shortenId
|
1845
|
-
? systemConfig.shortenId
|
1846
|
-
: ALL_ACTION_SHORTEN_ID,
|
1847
|
-
};
|
1848
|
-
let el = document.querySelector(`.${KARTE_MODAL_ROOT}[data-${KARTE_ACTION_RID}='${actionId}']`);
|
1849
|
-
if (el == null) {
|
1850
|
-
el = h('div', rootAttrs);
|
1851
|
-
document.body.appendChild(el);
|
1852
|
-
}
|
1853
|
-
const isShadow = !!document.body.attachShadow && useShadow;
|
1854
|
-
if (isShadow) {
|
1855
|
-
return el.shadowRoot ?? el.attachShadow({ mode: 'open' });
|
1856
|
-
}
|
1857
|
-
else {
|
1858
|
-
return el;
|
1551
|
+
function onDestroy(fn) {
|
1552
|
+
let { onDestroyHandlers } = getInternalHandlers();
|
1553
|
+
if (!onDestroyHandlers) {
|
1554
|
+
onDestroyHandlers = [];
|
1859
1555
|
}
|
1556
|
+
onDestroyHandlers.push(fn);
|
1557
|
+
setInternalHandlers({ onDestroyHandlers });
|
1860
1558
|
}
|
1861
|
-
/**
|
1862
|
-
|
1863
|
-
|
1864
|
-
|
1865
|
-
|
1866
|
-
|
1867
|
-
|
1868
|
-
|
1869
|
-
|
1870
|
-
|
1559
|
+
/**
|
1560
|
+
* 非推奨
|
1561
|
+
*
|
1562
|
+
* @deprecated 非推奨
|
1563
|
+
*
|
1564
|
+
* @internal
|
1565
|
+
*/
|
1566
|
+
const showModal = create;
|
1567
|
+
/**
|
1568
|
+
* 非推奨
|
1569
|
+
*
|
1570
|
+
* @deprecated 非推奨
|
1571
|
+
*
|
1572
|
+
* @internal
|
1573
|
+
*/
|
1574
|
+
const ensureModalRoot = ensureActionRoot;
|
1575
|
+
/**
|
1576
|
+
* 非推奨
|
1577
|
+
*
|
1578
|
+
* @deprecated 非推奨
|
1579
|
+
*
|
1580
|
+
* @internal
|
1581
|
+
*/
|
1582
|
+
function createApp(App, options = {
|
1583
|
+
send: () => { },
|
1584
|
+
publish: () => { },
|
1585
|
+
props: {},
|
1586
|
+
variables: {},
|
1587
|
+
localVariablesQuery: undefined,
|
1588
|
+
}) {
|
1589
|
+
let app = null;
|
1590
|
+
const close = () => {
|
1591
|
+
if (app) {
|
1592
|
+
app.$destroy();
|
1593
|
+
app = null;
|
1871
1594
|
}
|
1595
|
+
};
|
1596
|
+
const appArgs = {
|
1597
|
+
target: null,
|
1598
|
+
props: {
|
1599
|
+
send: options.send,
|
1600
|
+
publish: options.publish,
|
1601
|
+
close,
|
1602
|
+
data: {
|
1603
|
+
...options.props,
|
1604
|
+
...options.variables,
|
1605
|
+
},
|
1606
|
+
},
|
1607
|
+
};
|
1608
|
+
{
|
1609
|
+
const win = ensureModalRoot(true);
|
1610
|
+
appArgs.target = win;
|
1872
1611
|
}
|
1873
|
-
|
1874
|
-
|
1875
|
-
|
1876
|
-
|
1877
|
-
|
1612
|
+
return {
|
1613
|
+
close,
|
1614
|
+
show: () => {
|
1615
|
+
if (app) {
|
1616
|
+
return;
|
1617
|
+
}
|
1618
|
+
options.send('message_open');
|
1619
|
+
app = new App(appArgs);
|
1620
|
+
},
|
1621
|
+
};
|
1622
|
+
}
|
1623
|
+
/**
|
1624
|
+
* 非推奨
|
1625
|
+
*
|
1626
|
+
* @deprecated 非推奨
|
1627
|
+
*
|
1628
|
+
* @internal
|
1629
|
+
*/
|
1630
|
+
function destroy() {
|
1631
|
+
setDestroyed(true);
|
1632
|
+
dispatchDestroyEvent();
|
1633
|
+
}
|
1878
1634
|
/**
|
1879
1635
|
* 非推奨
|
1880
1636
|
*
|
@@ -1907,19 +1663,129 @@ function createFog({ color = '#000', opacity = '50%', zIndex = 999, onclick, })
|
|
1907
1663
|
root.appendChild(fog);
|
1908
1664
|
return { fog, close };
|
1909
1665
|
}
|
1666
|
+
|
1910
1667
|
/**
|
1911
|
-
*
|
1668
|
+
* スクリプト接客が利用するコードの管理
|
1669
|
+
*/
|
1670
|
+
/**
|
1671
|
+
* ES Modules に対応していない JavaScript をページに読み込む
|
1912
1672
|
*
|
1913
|
-
* @
|
1673
|
+
* @param src - JavaScript ファイルのリンク URL
|
1914
1674
|
*
|
1915
1675
|
* @public
|
1916
1676
|
*/
|
1917
|
-
function
|
1918
|
-
|
1919
|
-
|
1920
|
-
|
1677
|
+
async function loadGlobalScript(src) {
|
1678
|
+
return new Promise((resolve, reject) => {
|
1679
|
+
const script = document.createElement('script');
|
1680
|
+
script.src = src;
|
1681
|
+
document.body.appendChild(script);
|
1682
|
+
script.addEventListener('load', () => resolve(script));
|
1683
|
+
script.addEventListener('error', () => reject(script));
|
1684
|
+
});
|
1685
|
+
}
|
1686
|
+
/**
|
1687
|
+
* グローバル CSS をページに適用する
|
1688
|
+
*
|
1689
|
+
* @param css - CSS
|
1690
|
+
*
|
1691
|
+
* @public
|
1692
|
+
*/
|
1693
|
+
async function applyGlobalCss(css) {
|
1694
|
+
return new Promise((resolve, reject) => {
|
1695
|
+
const style = document.createElement('style');
|
1696
|
+
style.textContent = css;
|
1697
|
+
document.body.appendChild(style);
|
1698
|
+
style.addEventListener('load', () => resolve(style));
|
1699
|
+
style.addEventListener('error', () => reject(style));
|
1700
|
+
});
|
1701
|
+
}
|
1702
|
+
/**
|
1703
|
+
* style ファイルをページに読み込む
|
1704
|
+
*
|
1705
|
+
* @param href - style ファイルのリンク URL
|
1706
|
+
*
|
1707
|
+
* @public
|
1708
|
+
*/
|
1709
|
+
async function loadGlobalStyle(href) {
|
1710
|
+
return new Promise((resolve, reject) => {
|
1711
|
+
const link = document.createElement('link');
|
1712
|
+
link.rel = 'stylesheet';
|
1713
|
+
link.href = href;
|
1714
|
+
document.body.appendChild(link);
|
1715
|
+
link.addEventListener('load', () => resolve(link));
|
1716
|
+
link.addEventListener('error', () => reject(link));
|
1717
|
+
});
|
1718
|
+
}
|
1719
|
+
|
1720
|
+
/**
|
1721
|
+
* モーダル(ポップアップ)に関連するコードの管理
|
1722
|
+
*
|
1723
|
+
* アクションのShow, Close, ChangeStateの状態はここで管理する。
|
1724
|
+
*/
|
1725
|
+
/**
|
1726
|
+
* アクションが表示 (show) された後にフックする関数
|
1727
|
+
*
|
1728
|
+
* @param fn - 呼び出されるフック関数
|
1729
|
+
*
|
1730
|
+
* @public
|
1731
|
+
*/
|
1732
|
+
function onShow(fn) {
|
1733
|
+
let { onShowHandlers } = getInternalHandlers();
|
1734
|
+
if (!onShowHandlers) {
|
1735
|
+
onShowHandlers = [];
|
1921
1736
|
}
|
1922
|
-
|
1737
|
+
onShowHandlers.push(fn);
|
1738
|
+
setInternalHandlers({ onShowHandlers });
|
1739
|
+
}
|
1740
|
+
/**
|
1741
|
+
* アクションがクローズ (close) される前にフックする関数
|
1742
|
+
*
|
1743
|
+
* @param fn - 呼び出されるフック関数
|
1744
|
+
*
|
1745
|
+
* @public
|
1746
|
+
*/
|
1747
|
+
function onClose(fn) {
|
1748
|
+
let { onCloseHandlers } = getInternalHandlers();
|
1749
|
+
if (!onCloseHandlers) {
|
1750
|
+
onCloseHandlers = [];
|
1751
|
+
}
|
1752
|
+
onCloseHandlers.push(fn);
|
1753
|
+
setInternalHandlers({ onCloseHandlers });
|
1754
|
+
}
|
1755
|
+
/**
|
1756
|
+
* アクションのステートが変更された (changeState) 後にフックする関数
|
1757
|
+
*
|
1758
|
+
* @param fn - 呼び出されるフック関数
|
1759
|
+
*
|
1760
|
+
* @public
|
1761
|
+
*/
|
1762
|
+
function onChangeState(fn) {
|
1763
|
+
let { onChangeStateHandlers } = getInternalHandlers();
|
1764
|
+
if (!onChangeStateHandlers) {
|
1765
|
+
onChangeStateHandlers = [];
|
1766
|
+
}
|
1767
|
+
onChangeStateHandlers.push(fn);
|
1768
|
+
setInternalHandlers({ onChangeStateHandlers });
|
1769
|
+
}
|
1770
|
+
/**
|
1771
|
+
* アクションを表示する
|
1772
|
+
*
|
1773
|
+
* @public
|
1774
|
+
*/
|
1775
|
+
function showAction() {
|
1776
|
+
const event = new CustomEvent(ACTION_SHOW_EVENT, { detail: { trigger: 'custom' } });
|
1777
|
+
window.dispatchEvent(event);
|
1778
|
+
}
|
1779
|
+
/**
|
1780
|
+
* アクションを閉じる
|
1781
|
+
*
|
1782
|
+
* @param trigger - 閉じた時のトリガー。デフォルト `'none'`
|
1783
|
+
*
|
1784
|
+
* @public
|
1785
|
+
*/
|
1786
|
+
function closeAction(trigger = 'none') {
|
1787
|
+
const event = new CustomEvent(ACTION_CLOSE_EVENT, { detail: { trigger } });
|
1788
|
+
window.dispatchEvent(event);
|
1923
1789
|
}
|
1924
1790
|
/**
|
1925
1791
|
* アクションに CSS を適用する
|
@@ -1934,7 +1800,7 @@ async function applyCss(css) {
|
|
1934
1800
|
return new Promise((resolve, reject) => {
|
1935
1801
|
const style = document.createElement('style');
|
1936
1802
|
style.textContent = css;
|
1937
|
-
const shadowRoot =
|
1803
|
+
const shadowRoot = getActionRoot();
|
1938
1804
|
if (!shadowRoot)
|
1939
1805
|
return;
|
1940
1806
|
shadowRoot.append(style);
|
@@ -1973,7 +1839,7 @@ async function fixFontFaceIssue(href, cssRules) {
|
|
1973
1839
|
* @public
|
1974
1840
|
*/
|
1975
1841
|
async function loadStyle(href) {
|
1976
|
-
const sr =
|
1842
|
+
const sr = getActionRoot();
|
1977
1843
|
if (!sr)
|
1978
1844
|
return;
|
1979
1845
|
let cssRules = '';
|
@@ -2000,111 +1866,32 @@ async function loadStyle(href) {
|
|
2000
1866
|
// Chromeのバグで、ページとShadow Rootの両方に、@font-faceを設定する必要がある
|
2001
1867
|
// @see https://stackoverflow.com/a/63717709
|
2002
1868
|
// @ts-ignore
|
2003
|
-
document.adoptedStyleSheets = [...document.adoptedStyleSheets, css, fontFaceCss];
|
2004
|
-
}
|
2005
|
-
//
|
2006
|
-
|
2007
|
-
|
2008
|
-
|
2009
|
-
|
2010
|
-
|
2011
|
-
|
2012
|
-
|
2013
|
-
const showModal = create;
|
2014
|
-
/**
|
2015
|
-
* 非推奨
|
2016
|
-
*
|
2017
|
-
* @deprecated 非推奨
|
2018
|
-
*
|
2019
|
-
* @internal
|
2020
|
-
*/
|
2021
|
-
const KARTE_MODAL_ROOT = 'karte-modal-root';
|
2022
|
-
/**
|
2023
|
-
* 非推奨
|
2024
|
-
*
|
2025
|
-
* @deprecated 非推奨
|
2026
|
-
*
|
2027
|
-
* @internal
|
2028
|
-
*/
|
2029
|
-
const ensureModalRoot = ensureActionRoot;
|
2030
|
-
/**
|
2031
|
-
* 非推奨
|
2032
|
-
*
|
2033
|
-
* @deprecated 非推奨
|
2034
|
-
*
|
2035
|
-
* @internal
|
2036
|
-
*/
|
2037
|
-
const show = showAction;
|
2038
|
-
/**
|
2039
|
-
* 非推奨
|
2040
|
-
*
|
2041
|
-
* @deprecated 非推奨
|
2042
|
-
*
|
2043
|
-
* @internal
|
2044
|
-
*/
|
2045
|
-
const close = closeAction;
|
2046
|
-
/**
|
2047
|
-
* 非推奨
|
2048
|
-
*
|
2049
|
-
* @deprecated 非推奨
|
2050
|
-
*
|
2051
|
-
* @internal
|
2052
|
-
*/
|
2053
|
-
function createApp(App, options = {
|
2054
|
-
send: () => { },
|
2055
|
-
publish: () => { },
|
2056
|
-
props: {},
|
2057
|
-
variables: {},
|
2058
|
-
localVariablesQuery: undefined,
|
2059
|
-
}) {
|
2060
|
-
let app = null;
|
2061
|
-
const close = () => {
|
2062
|
-
if (app) {
|
2063
|
-
app.$destroy();
|
2064
|
-
app = null;
|
2065
|
-
}
|
2066
|
-
};
|
2067
|
-
const appArgs = {
|
2068
|
-
target: null,
|
2069
|
-
props: {
|
2070
|
-
send: options.send,
|
2071
|
-
publish: options.publish,
|
2072
|
-
close,
|
2073
|
-
data: {
|
2074
|
-
...options.props,
|
2075
|
-
...options.variables,
|
2076
|
-
},
|
2077
|
-
},
|
2078
|
-
};
|
2079
|
-
{
|
2080
|
-
const win = ensureModalRoot(true);
|
2081
|
-
appArgs.target = win;
|
2082
|
-
}
|
2083
|
-
return {
|
2084
|
-
close,
|
2085
|
-
show: () => {
|
2086
|
-
if (app) {
|
2087
|
-
return;
|
2088
|
-
}
|
2089
|
-
options.send('message_open');
|
2090
|
-
app = new App(appArgs);
|
2091
|
-
},
|
2092
|
-
};
|
1869
|
+
document.adoptedStyleSheets = [...document.adoptedStyleSheets, css, fontFaceCss];
|
1870
|
+
}
|
1871
|
+
// @internal
|
1872
|
+
function getCssVariables(data) {
|
1873
|
+
return Object.entries(data)
|
1874
|
+
.filter(([key, value]) => {
|
1875
|
+
return ['string', 'number'].includes(typeof value) && key.startsWith('--');
|
1876
|
+
})
|
1877
|
+
.map(([key, value]) => `${key}:${value}`)
|
1878
|
+
.join(';');
|
2093
1879
|
}
|
2094
1880
|
/**
|
2095
|
-
*
|
1881
|
+
* アクションのルートの DOM 要素を取得する
|
2096
1882
|
*
|
2097
|
-
* @
|
1883
|
+
* @returns アクションがルートの DOM 要素 を持つ場合は DOM 要素を返します。ない場合は `null` を返します
|
2098
1884
|
*
|
2099
|
-
* @
|
1885
|
+
* @public
|
2100
1886
|
*/
|
2101
|
-
function
|
1887
|
+
function getActionRoot() {
|
2102
1888
|
const root = document.querySelector(`.${KARTE_ACTION_ROOT}[data-${KARTE_ACTION_RID}='${actionId}']`);
|
2103
1889
|
if (!root?.shadowRoot) {
|
2104
1890
|
return null;
|
2105
1891
|
}
|
2106
1892
|
return root.shadowRoot;
|
2107
1893
|
}
|
1894
|
+
// -------- The following codes are deprecated --------
|
2108
1895
|
/**
|
2109
1896
|
* 非推奨
|
2110
1897
|
*
|
@@ -2112,13 +1899,18 @@ function getActionShadowRoot() {
|
|
2112
1899
|
*
|
2113
1900
|
* @internal
|
2114
1901
|
*/
|
2115
|
-
|
2116
|
-
|
2117
|
-
|
2118
|
-
|
1902
|
+
const show = showAction;
|
1903
|
+
/**
|
1904
|
+
* 非推奨
|
1905
|
+
*
|
1906
|
+
* @deprecated 非推奨
|
1907
|
+
*
|
1908
|
+
* @internal
|
1909
|
+
*/
|
1910
|
+
const close = closeAction;
|
2119
1911
|
|
2120
1912
|
/**
|
2121
|
-
* Widget API 互換のインターフェース
|
1913
|
+
* エディタv1のWidget API 互換のインターフェース
|
2122
1914
|
*/
|
2123
1915
|
const STORE_LS_KEY_PREFIX = 'krt___';
|
2124
1916
|
const valCallbacks = {};
|
@@ -2635,6 +2427,232 @@ class StateItem extends SvelteComponent {
|
|
2635
2427
|
}
|
2636
2428
|
}
|
2637
2429
|
|
2430
|
+
function isEmpty(value) {
|
2431
|
+
if (Array.isArray(value)) {
|
2432
|
+
return value.length === 0;
|
2433
|
+
}
|
2434
|
+
else {
|
2435
|
+
return !value;
|
2436
|
+
}
|
2437
|
+
}
|
2438
|
+
/** @internal */
|
2439
|
+
function registerInput({ name, statePath, validator = () => true, initialValue, }) {
|
2440
|
+
const writableValue = {
|
2441
|
+
subscribe(run) {
|
2442
|
+
return formData.subscribe(formData => {
|
2443
|
+
run(formData[name]?.value);
|
2444
|
+
});
|
2445
|
+
},
|
2446
|
+
set(value) {
|
2447
|
+
formData.update(prev => ({
|
2448
|
+
...prev,
|
2449
|
+
[name]: {
|
2450
|
+
statePath,
|
2451
|
+
value,
|
2452
|
+
isValid: validator(value),
|
2453
|
+
},
|
2454
|
+
}));
|
2455
|
+
},
|
2456
|
+
update(updater) {
|
2457
|
+
formData.update(prev => {
|
2458
|
+
const prevValue = prev[name]?.value;
|
2459
|
+
return {
|
2460
|
+
...prev,
|
2461
|
+
[name]: {
|
2462
|
+
statePath,
|
2463
|
+
value: updater(prevValue),
|
2464
|
+
isValid: validator(prevValue),
|
2465
|
+
},
|
2466
|
+
};
|
2467
|
+
});
|
2468
|
+
},
|
2469
|
+
};
|
2470
|
+
if (isEmpty(get(writableValue))) {
|
2471
|
+
writableValue.set(initialValue);
|
2472
|
+
}
|
2473
|
+
return writableValue;
|
2474
|
+
}
|
2475
|
+
/** @internal */
|
2476
|
+
const getValuesAreValidReader = statePath => ({
|
2477
|
+
subscribe(callback) {
|
2478
|
+
return formData.subscribe(formData => {
|
2479
|
+
const valuesAreValid = Object.entries(formData)
|
2480
|
+
.filter(([_, { statePath: s }]) => s === statePath) // eslint-disable-line @typescript-eslint/no-unused-vars
|
2481
|
+
.every(([_, { isValid }]) => isValid); // eslint-disable-line @typescript-eslint/no-unused-vars
|
2482
|
+
callback(valuesAreValid);
|
2483
|
+
});
|
2484
|
+
},
|
2485
|
+
});
|
2486
|
+
function formDataToEventValues(campaignId, formData) {
|
2487
|
+
const questions = [];
|
2488
|
+
const answersMap = {};
|
2489
|
+
Object.entries(formData).forEach(([name, dataItem]) => {
|
2490
|
+
questions.push(name);
|
2491
|
+
const value = dataItem.value;
|
2492
|
+
const answerKey = `question_${name}`;
|
2493
|
+
if (Array.isArray(value)) {
|
2494
|
+
answersMap[answerKey] = {
|
2495
|
+
choices: value,
|
2496
|
+
};
|
2497
|
+
}
|
2498
|
+
else if (typeof value === 'string') {
|
2499
|
+
answersMap[answerKey] = {
|
2500
|
+
free_answer: value,
|
2501
|
+
};
|
2502
|
+
}
|
2503
|
+
});
|
2504
|
+
return {
|
2505
|
+
[campaignId]: {
|
2506
|
+
questions,
|
2507
|
+
...answersMap,
|
2508
|
+
},
|
2509
|
+
};
|
2510
|
+
}
|
2511
|
+
/** @internal */
|
2512
|
+
function submit() {
|
2513
|
+
const systemConfig = getSystem();
|
2514
|
+
const campaignId = systemConfig.campaignId;
|
2515
|
+
if (campaignId) {
|
2516
|
+
const formData$1 = get(formData);
|
2517
|
+
const values = formDataToEventValues(campaignId, formData$1);
|
2518
|
+
return values;
|
2519
|
+
}
|
2520
|
+
return {};
|
2521
|
+
}
|
2522
|
+
|
2523
|
+
/**
|
2524
|
+
* モーダル(ポップアップ)のコンポーネントが利用するコードの管理
|
2525
|
+
*/
|
2526
|
+
function _moveTo(to) {
|
2527
|
+
window.dispatchEvent(new CustomEvent(ACTION_CHANGE_STATE_EVENT, { detail: { to, actionId } }));
|
2528
|
+
}
|
2529
|
+
/** @internal */
|
2530
|
+
const moveTo = (to) => () => {
|
2531
|
+
_moveTo(to);
|
2532
|
+
};
|
2533
|
+
/** @internal */
|
2534
|
+
const linkTo = (to, targetBlank = true) => () => {
|
2535
|
+
send_event('message_click', { url: to, state: getState$1() });
|
2536
|
+
if (targetBlank) {
|
2537
|
+
window.open(to);
|
2538
|
+
}
|
2539
|
+
else {
|
2540
|
+
location.href = to;
|
2541
|
+
}
|
2542
|
+
};
|
2543
|
+
/** @internal */
|
2544
|
+
const closeApp = (trigger) => () => {
|
2545
|
+
window.dispatchEvent(new CustomEvent(ACTION_CLOSE_EVENT, { detail: { trigger } }));
|
2546
|
+
};
|
2547
|
+
/** @internal */
|
2548
|
+
const runScript = (handlerName) => () => {
|
2549
|
+
const handlers = getEventHandlers();
|
2550
|
+
const handler = handlers[handlerName];
|
2551
|
+
if (!handler)
|
2552
|
+
return;
|
2553
|
+
try {
|
2554
|
+
handler();
|
2555
|
+
}
|
2556
|
+
catch (e) {
|
2557
|
+
console.warn('Failed to run custom handler', handlerName, e);
|
2558
|
+
}
|
2559
|
+
};
|
2560
|
+
/** @internal */
|
2561
|
+
const submitForm = (to) => () => {
|
2562
|
+
const values = submit();
|
2563
|
+
send_event('_answer_question', values);
|
2564
|
+
_moveTo(to);
|
2565
|
+
};
|
2566
|
+
/** @internal */
|
2567
|
+
const execOnClickOperation = (onClickOperation) => {
|
2568
|
+
if (onClickOperation.operation === 'linkTo') {
|
2569
|
+
linkTo(...onClickOperation.args)();
|
2570
|
+
}
|
2571
|
+
else if (onClickOperation.operation === 'moveTo') {
|
2572
|
+
moveTo(...onClickOperation.args)();
|
2573
|
+
}
|
2574
|
+
else if (onClickOperation.operation === 'closeApp') {
|
2575
|
+
closeApp(onClickOperation.args[0] || 'button')();
|
2576
|
+
}
|
2577
|
+
else if (onClickOperation.operation === 'runScript') {
|
2578
|
+
runScript(onClickOperation.args[0])();
|
2579
|
+
}
|
2580
|
+
else if (onClickOperation.operation === 'submitForm') {
|
2581
|
+
submitForm(onClickOperation.args[0])();
|
2582
|
+
}
|
2583
|
+
};
|
2584
|
+
/** @internal */
|
2585
|
+
const haveFunction = (onClickOperation) => {
|
2586
|
+
return onClickOperation.operation !== 'none';
|
2587
|
+
};
|
2588
|
+
function getAnimation(animation) {
|
2589
|
+
switch (animation.type) {
|
2590
|
+
case 'fade':
|
2591
|
+
return `opacity: ${animation.progress}`;
|
2592
|
+
case 'bounce': {
|
2593
|
+
const translateX = animation.x;
|
2594
|
+
const translateY = animation.y;
|
2595
|
+
return `transform: translate3d(${translateX}%, ${translateY}%, 0) scale(${animation.progress});`;
|
2596
|
+
}
|
2597
|
+
case 'slide-down': {
|
2598
|
+
const translateX = animation.x;
|
2599
|
+
const translateY = animation.y - 100 * (1 - animation.progress);
|
2600
|
+
return `transform: translate3d(${translateX}%, ${translateY}%, 0);`;
|
2601
|
+
}
|
2602
|
+
case 'slide-up': {
|
2603
|
+
const translateX = animation.x;
|
2604
|
+
const translateY = animation.y + 100 * (1 - animation.progress);
|
2605
|
+
return `transform: translate3d(${translateX}%, ${translateY}%, 0);`;
|
2606
|
+
}
|
2607
|
+
case 'slide-left': {
|
2608
|
+
const translateX = animation.x + 100 * (1 - animation.progress);
|
2609
|
+
const translateY = animation.y;
|
2610
|
+
return `transform: translate3d(${translateX}%, ${translateY}%, 0);`;
|
2611
|
+
}
|
2612
|
+
case 'slide-right': {
|
2613
|
+
const translateX = animation.x - 100 * (1 - animation.progress);
|
2614
|
+
const translateY = animation.y;
|
2615
|
+
return `transform: translate3d(${translateX}%, ${translateY}%, 0);`;
|
2616
|
+
}
|
2617
|
+
case 'none': {
|
2618
|
+
const translateX = animation.x;
|
2619
|
+
const translateY = animation.y;
|
2620
|
+
return `transform: translate3d(${translateX}%, ${translateY}%, 0);`;
|
2621
|
+
}
|
2622
|
+
default:
|
2623
|
+
console.warn(`[action-sdk] invalid '${animation}', so we use 'transform: none' instead`);
|
2624
|
+
return 'transform: none';
|
2625
|
+
}
|
2626
|
+
}
|
2627
|
+
const EASING = {
|
2628
|
+
fade: linear,
|
2629
|
+
bounce: elasticOut,
|
2630
|
+
'slide-down': cubicOut,
|
2631
|
+
'slide-up': cubicOut,
|
2632
|
+
'slide-left': cubicOut,
|
2633
|
+
'slide-right': cubicOut,
|
2634
|
+
none: linear,
|
2635
|
+
};
|
2636
|
+
/**
|
2637
|
+
* The function to activate svelte animation.
|
2638
|
+
*
|
2639
|
+
* @param node - A target node of animation. This argument is passed by svelte, by default.
|
2640
|
+
* @param customAnimationOptions - A custom animation option object
|
2641
|
+
*
|
2642
|
+
* @see {@link https://svelte.dev/docs#template-syntax-element-directives-transition-fn-custom-transition-functions| Custom transition functions} for detail documentation
|
2643
|
+
*
|
2644
|
+
* @internal
|
2645
|
+
*/
|
2646
|
+
function customAnimation(node, { transform, animationStyle, delay = 0, duration = 1000 }) {
|
2647
|
+
const [x, y] = transform;
|
2648
|
+
return {
|
2649
|
+
delay,
|
2650
|
+
duration,
|
2651
|
+
easing: EASING[animationStyle],
|
2652
|
+
css: (progress) => getAnimation({ type: animationStyle, x, y, progress }),
|
2653
|
+
};
|
2654
|
+
}
|
2655
|
+
|
2638
2656
|
/* src/components/BackgroundOverray.svelte generated by Svelte v3.53.1 */
|
2639
2657
|
|
2640
2658
|
function add_css$s(target) {
|
@@ -2730,7 +2748,7 @@ function add_css$r(target) {
|
|
2730
2748
|
append_styles(target, "svelte-1tg0tf", ".button.svelte-1tg0tf{display:block;text-decoration:none;color:inherit;border:none;background:none;margin:0;padding:0}.button.svelte-1tg0tf:link,.button.svelte-1tg0tf:visited,.button.svelte-1tg0tf:active,.button.svelte-1tg0tf:hover{color:inherit}");
|
2731
2749
|
}
|
2732
2750
|
|
2733
|
-
// (
|
2751
|
+
// (49:0) {:else}
|
2734
2752
|
function create_else_block$3(ctx) {
|
2735
2753
|
let button;
|
2736
2754
|
let current;
|
@@ -2798,7 +2816,7 @@ function create_else_block$3(ctx) {
|
|
2798
2816
|
};
|
2799
2817
|
}
|
2800
2818
|
|
2801
|
-
// (
|
2819
|
+
// (45:39)
|
2802
2820
|
function create_if_block_2(ctx) {
|
2803
2821
|
let div;
|
2804
2822
|
let current;
|
@@ -2857,7 +2875,7 @@ function create_if_block_2(ctx) {
|
|
2857
2875
|
};
|
2858
2876
|
}
|
2859
2877
|
|
2860
|
-
// (
|
2878
|
+
// (41:41)
|
2861
2879
|
function create_if_block_1$2(ctx) {
|
2862
2880
|
let a;
|
2863
2881
|
let a_href_value;
|
@@ -2937,7 +2955,7 @@ function create_if_block_1$2(ctx) {
|
|
2937
2955
|
};
|
2938
2956
|
}
|
2939
2957
|
|
2940
|
-
// (
|
2958
|
+
// (37:0) {#if disabled}
|
2941
2959
|
function create_if_block$6(ctx) {
|
2942
2960
|
let div;
|
2943
2961
|
let current;
|
@@ -3166,7 +3184,7 @@ function add_css$q(target) {
|
|
3166
3184
|
append_styles(target, "svelte-yyiwdt", ".modal.svelte-yyiwdt{position:fixed;box-sizing:border-box;z-index:2147483647;display:flex}.modal.svelte-yyiwdt > .button{flex:auto;display:flex}.close.svelte-yyiwdt{position:absolute;top:0;right:0}.close.svelte-yyiwdt > .button{position:absolute;display:flex;justify-content:center;align-items:center;background-color:transparent;border:none;cursor:pointer;padding:0;transition:all 0.25s}.close.svelte-yyiwdt > .button:hover{transform:rotate(90deg)}.modal-content.svelte-yyiwdt{flex:auto;display:flex;justify-content:center;align-items:center}");
|
3167
3185
|
}
|
3168
3186
|
|
3169
|
-
// (
|
3187
|
+
// (146:0) {#if visible}
|
3170
3188
|
function create_if_block$5(ctx) {
|
3171
3189
|
let div;
|
3172
3190
|
let button;
|
@@ -3245,7 +3263,7 @@ function create_if_block$5(ctx) {
|
|
3245
3263
|
};
|
3246
3264
|
}
|
3247
3265
|
|
3248
|
-
// (
|
3266
|
+
// (163:6) {#if closable}
|
3249
3267
|
function create_if_block_1$1(ctx) {
|
3250
3268
|
let div;
|
3251
3269
|
let button;
|
@@ -3307,7 +3325,7 @@ function create_if_block_1$1(ctx) {
|
|
3307
3325
|
};
|
3308
3326
|
}
|
3309
3327
|
|
3310
|
-
// (
|
3328
|
+
// (165:10) <Button onClick={onClose} style={_closeStyle} eventName={closeEventName} eventValue={closeEventValue}>
|
3311
3329
|
function create_default_slot_1$1(ctx) {
|
3312
3330
|
let svg;
|
3313
3331
|
let path;
|
@@ -3340,7 +3358,7 @@ function create_default_slot_1$1(ctx) {
|
|
3340
3358
|
};
|
3341
3359
|
}
|
3342
3360
|
|
3343
|
-
// (
|
3361
|
+
// (162:4) <Button {onClick} eventName={clickEventName} eventValue={clickEventValue}>
|
3344
3362
|
function create_default_slot$6(ctx) {
|
3345
3363
|
let t;
|
3346
3364
|
let div;
|