@plaidev/karte-action-sdk 1.1.267 → 1.1.268-29083022.42c3d847
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.js +7113 -7045
- package/dist/index.es.js +6248 -6239
- package/dist/svelte5/hydrate/index.es.d.ts +1 -1
- package/dist/svelte5/hydrate/index.es.js +500 -350
- package/dist/svelte5/index.es.d.ts +1 -1
- package/dist/svelte5/index.es.js +386 -385
- package/dist/svelte5/index.front2.es.js +386 -385
- package/package.json +1 -1
@@ -38,9 +38,15 @@ const KARTE_MODAL_ROOT = 'karte-modal-root';
|
|
38
38
|
/** @internal */
|
39
39
|
const NOOP = (_args) => { }; // eslint-disable-line @typescript-eslint/no-unused-vars
|
40
40
|
/** @internal */
|
41
|
-
const isPreview = () =>
|
42
|
-
|
43
|
-
|
41
|
+
const isPreview = () => (isInFrame() );
|
42
|
+
const isCanvasPreview = () => typeof document !== 'undefined'
|
43
|
+
? (document?.querySelector('#preview')?.getAttribute('data-canvas-preview') ?? 'false') ===
|
44
|
+
'true'
|
45
|
+
: false;
|
46
|
+
const isOnSite = () => typeof document !== 'undefined'
|
47
|
+
? (document?.querySelector('#preview')?.getAttribute('data-on-site') ?? 'true') === 'true'
|
48
|
+
: true;
|
49
|
+
const isInFrame = () => window && window.self !== window.top;
|
44
50
|
/** @internal */
|
45
51
|
const setPreviousFocus = () => {
|
46
52
|
const previously_focused = typeof document !== 'undefined' && document.activeElement;
|
@@ -758,6 +764,8 @@ const state = writable('/');
|
|
758
764
|
* @public
|
759
765
|
*/
|
760
766
|
function setState$1(stateId, options) {
|
767
|
+
if (isPreview() && options?.disableInPreview)
|
768
|
+
return;
|
761
769
|
state.set(stateId);
|
762
770
|
}
|
763
771
|
/**
|
@@ -1168,7 +1176,9 @@ function cloneToJson(data) {
|
|
1168
1176
|
|
1169
1177
|
// prettier-ignore
|
1170
1178
|
/** @internal */
|
1171
|
-
const actionId =
|
1179
|
+
const actionId = isPreview()
|
1180
|
+
? ALL_ACTION_ID
|
1181
|
+
: typeof __FLYER_GEN_ACTION_ID_ON_BUILD__ === 'string'
|
1172
1182
|
? __FLYER_GEN_ACTION_ID_ON_BUILD__
|
1173
1183
|
: randStr();
|
1174
1184
|
/** @internal */
|
@@ -1576,7 +1586,9 @@ const loadActionTableQuery = async (config, data, api_key, collection_endpoint)
|
|
1576
1586
|
/** @internal */
|
1577
1587
|
const loadActionTable = async (config, data, api_key, collection_endpoint) => {
|
1578
1588
|
console.debug('[debug] loadActionTable', isPreview(), api_key, collection_endpoint, JSON.stringify(config));
|
1579
|
-
const results =
|
1589
|
+
const results = isPreview()
|
1590
|
+
? config.map(c => c.preview_value)
|
1591
|
+
: await Promise.all(config
|
1580
1592
|
.filter(c => c.resolver === 'action-table-row' ||
|
1581
1593
|
c.resolver === 'action-table-rows' ||
|
1582
1594
|
c.resolver === 'action-table-query')
|
@@ -1623,6 +1635,32 @@ function initActionTable(localVariablesQuery) {
|
|
1623
1635
|
setVariables(initValues);
|
1624
1636
|
}
|
1625
1637
|
|
1638
|
+
/**
|
1639
|
+
* モーダル(ポップアップ)に関連するコードの管理
|
1640
|
+
*
|
1641
|
+
* アクションのShow, Close, ChangeStateの状態はここで管理する。
|
1642
|
+
*/
|
1643
|
+
/**
|
1644
|
+
* アクションを表示する
|
1645
|
+
*
|
1646
|
+
* @public
|
1647
|
+
*/
|
1648
|
+
function showAction$1() {
|
1649
|
+
const event = new CustomEvent(ACTION_SHOW_EVENT, { detail: { trigger: 'custom' } });
|
1650
|
+
window.dispatchEvent(event);
|
1651
|
+
}
|
1652
|
+
/**
|
1653
|
+
* アクションを閉じる
|
1654
|
+
*
|
1655
|
+
* @param trigger - 閉じた時のトリガー。デフォルト `'none'`
|
1656
|
+
*
|
1657
|
+
* @public
|
1658
|
+
*/
|
1659
|
+
function closeAction$1(trigger = 'none') {
|
1660
|
+
const event = new CustomEvent(ACTION_CLOSE_EVENT, { detail: { trigger } });
|
1661
|
+
window.dispatchEvent(event);
|
1662
|
+
}
|
1663
|
+
|
1626
1664
|
/**
|
1627
1665
|
* モーダル(ポップアップ)に関連するコードの管理
|
1628
1666
|
*
|
@@ -1640,12 +1678,57 @@ const handleState = (event) => {
|
|
1640
1678
|
});
|
1641
1679
|
}
|
1642
1680
|
};
|
1681
|
+
/**
|
1682
|
+
* アクションが表示 (show) された後にフックする関数
|
1683
|
+
*
|
1684
|
+
* @param fn - 呼び出されるフック関数
|
1685
|
+
*
|
1686
|
+
* @public
|
1687
|
+
*/
|
1688
|
+
function onShow(fn) {
|
1689
|
+
let { onShowHandlers } = getInternalHandlers();
|
1690
|
+
if (!onShowHandlers) {
|
1691
|
+
onShowHandlers = [];
|
1692
|
+
}
|
1693
|
+
onShowHandlers.push(fn);
|
1694
|
+
setInternalHandlers({ onShowHandlers });
|
1695
|
+
}
|
1696
|
+
/**
|
1697
|
+
* アクションがクローズ (close) される前にフックする関数
|
1698
|
+
*
|
1699
|
+
* @param fn - 呼び出されるフック関数
|
1700
|
+
*
|
1701
|
+
* @public
|
1702
|
+
*/
|
1703
|
+
function onClose(fn) {
|
1704
|
+
let { onCloseHandlers } = getInternalHandlers();
|
1705
|
+
if (!onCloseHandlers) {
|
1706
|
+
onCloseHandlers = [];
|
1707
|
+
}
|
1708
|
+
onCloseHandlers.push(fn);
|
1709
|
+
setInternalHandlers({ onCloseHandlers });
|
1710
|
+
}
|
1711
|
+
/**
|
1712
|
+
* アクションのステートが変更された (changeState) 後にフックする関数
|
1713
|
+
*
|
1714
|
+
* @param fn - 呼び出されるフック関数
|
1715
|
+
*
|
1716
|
+
* @public
|
1717
|
+
*/
|
1718
|
+
function onChangeState(fn) {
|
1719
|
+
let { onChangeStateHandlers } = getInternalHandlers();
|
1720
|
+
if (!onChangeStateHandlers) {
|
1721
|
+
onChangeStateHandlers = [];
|
1722
|
+
}
|
1723
|
+
onChangeStateHandlers.push(fn);
|
1724
|
+
setInternalHandlers({ onChangeStateHandlers });
|
1725
|
+
}
|
1643
1726
|
/**
|
1644
1727
|
* アクションを表示する
|
1645
1728
|
*
|
1646
1729
|
* @public
|
1647
1730
|
*/
|
1648
|
-
function showAction
|
1731
|
+
function showAction() {
|
1649
1732
|
const event = new CustomEvent(ACTION_SHOW_EVENT, { detail: { trigger: 'custom' } });
|
1650
1733
|
window.dispatchEvent(event);
|
1651
1734
|
}
|
@@ -1656,10 +1739,114 @@ function showAction$1() {
|
|
1656
1739
|
*
|
1657
1740
|
* @public
|
1658
1741
|
*/
|
1659
|
-
function closeAction
|
1742
|
+
function closeAction(trigger = 'none') {
|
1660
1743
|
const event = new CustomEvent(ACTION_CLOSE_EVENT, { detail: { trigger } });
|
1661
1744
|
window.dispatchEvent(event);
|
1662
1745
|
}
|
1746
|
+
/**
|
1747
|
+
* アクションに CSS を適用する
|
1748
|
+
*
|
1749
|
+
* @param css - 適用する CSS
|
1750
|
+
*
|
1751
|
+
* @returns 適用された style 要素を返す Promise
|
1752
|
+
*
|
1753
|
+
* @public
|
1754
|
+
*/
|
1755
|
+
async function applyCss(css) {
|
1756
|
+
return new Promise((resolve, reject) => {
|
1757
|
+
const style = document.createElement('style');
|
1758
|
+
style.textContent = css;
|
1759
|
+
const shadowRoot = getActionRoot();
|
1760
|
+
if (!shadowRoot)
|
1761
|
+
return;
|
1762
|
+
shadowRoot.append(style);
|
1763
|
+
style.addEventListener('load', () => resolve(style));
|
1764
|
+
style.addEventListener('error', () => reject(style));
|
1765
|
+
});
|
1766
|
+
}
|
1767
|
+
async function fixFontFaceIssue(href, cssRules) {
|
1768
|
+
const css = new CSSStyleSheet();
|
1769
|
+
// @ts-ignore
|
1770
|
+
await css.replace(cssRules);
|
1771
|
+
const rules = [];
|
1772
|
+
const fixedRules = [];
|
1773
|
+
Array.from(css.cssRules).forEach(cssRule => {
|
1774
|
+
if (cssRule.type !== 5) {
|
1775
|
+
rules.push(cssRule.cssText);
|
1776
|
+
}
|
1777
|
+
// type 5 is @font-face
|
1778
|
+
const split = href.split('/');
|
1779
|
+
const stylePath = split.slice(0, split.length - 1).join('/');
|
1780
|
+
const cssText = cssRule.cssText;
|
1781
|
+
const newCssText = cssText.replace(
|
1782
|
+
// relative paths
|
1783
|
+
/url\s*\(\s*['"]?(?!((\/)|((?:https?:)?\/\/)|(?:data:?:)))([^'")]+)['"]?\s*\)/g, `url("${stylePath}/$4")`);
|
1784
|
+
if (cssText === newCssText)
|
1785
|
+
return;
|
1786
|
+
fixedRules.push(newCssText);
|
1787
|
+
});
|
1788
|
+
return [rules.join('\n'), fixedRules.join('\n')];
|
1789
|
+
}
|
1790
|
+
/**
|
1791
|
+
* アクションにグローバルなスタイルを読み込む
|
1792
|
+
*
|
1793
|
+
* @param href - style ファイルのリンク URL
|
1794
|
+
*
|
1795
|
+
* @public
|
1796
|
+
*/
|
1797
|
+
async function loadStyle(href) {
|
1798
|
+
const sr = getActionRoot();
|
1799
|
+
if (!sr)
|
1800
|
+
return;
|
1801
|
+
let cssRules = '';
|
1802
|
+
try {
|
1803
|
+
const res = await fetch(href);
|
1804
|
+
cssRules = await res.text();
|
1805
|
+
}
|
1806
|
+
catch (_) {
|
1807
|
+
// pass
|
1808
|
+
}
|
1809
|
+
if (!cssRules)
|
1810
|
+
return;
|
1811
|
+
// Chromeのバグで、Shadow Rootの@font-faceを絶対パスで指定する必要がある
|
1812
|
+
// @see https://stackoverflow.com/a/63717709
|
1813
|
+
const [rules, fontFaceRules] = await fixFontFaceIssue(href, cssRules);
|
1814
|
+
const css = new CSSStyleSheet();
|
1815
|
+
// @ts-ignore
|
1816
|
+
await css.replace(rules);
|
1817
|
+
const fontFaceCss = new CSSStyleSheet();
|
1818
|
+
// @ts-ignore
|
1819
|
+
await fontFaceCss.replace(fontFaceRules);
|
1820
|
+
// @ts-ignore
|
1821
|
+
sr.adoptedStyleSheets = [...sr.adoptedStyleSheets, css, fontFaceCss];
|
1822
|
+
// Chromeのバグで、ページとShadow Rootの両方に、@font-faceを設定する必要がある
|
1823
|
+
// @see https://stackoverflow.com/a/63717709
|
1824
|
+
// @ts-ignore
|
1825
|
+
document.adoptedStyleSheets = [...document.adoptedStyleSheets, css, fontFaceCss];
|
1826
|
+
}
|
1827
|
+
// @internal
|
1828
|
+
function getCssVariables(data) {
|
1829
|
+
return Object.entries(data)
|
1830
|
+
.filter(([key, value]) => {
|
1831
|
+
return ['string', 'number'].includes(typeof value) && key.startsWith('--');
|
1832
|
+
})
|
1833
|
+
.map(([key, value]) => `${key}:${value}`)
|
1834
|
+
.join(';');
|
1835
|
+
}
|
1836
|
+
/**
|
1837
|
+
* アクションのルートの DOM 要素を取得する
|
1838
|
+
*
|
1839
|
+
* @returns アクションがルートの DOM 要素 を持つ場合は DOM 要素を返します。ない場合は `null` を返します
|
1840
|
+
*
|
1841
|
+
* @public
|
1842
|
+
*/
|
1843
|
+
function getActionRoot() {
|
1844
|
+
const root = document.querySelector(`.${KARTE_ACTION_ROOT}[data-${KARTE_ACTION_RID}='${actionId}']`);
|
1845
|
+
if (!root?.shadowRoot) {
|
1846
|
+
return null;
|
1847
|
+
}
|
1848
|
+
return root.shadowRoot;
|
1849
|
+
}
|
1663
1850
|
/** @internal */
|
1664
1851
|
function createModal(App, options = {
|
1665
1852
|
send: () => { },
|
@@ -1727,6 +1914,9 @@ function createModal(App, options = {
|
|
1727
1914
|
if (app) {
|
1728
1915
|
return;
|
1729
1916
|
}
|
1917
|
+
if (!isOnSite() && trigger === 'custom') {
|
1918
|
+
return;
|
1919
|
+
}
|
1730
1920
|
if (trigger === 'custom' && (options.props.show_on_scroll || options.props.show_on_time)) {
|
1731
1921
|
return;
|
1732
1922
|
}
|
@@ -1751,9 +1941,9 @@ function createModal(App, options = {
|
|
1751
1941
|
if (app) {
|
1752
1942
|
return;
|
1753
1943
|
}
|
1944
|
+
const target = ensureActionRoot(isOnSite());
|
1754
1945
|
const props = {
|
1755
|
-
target
|
1756
|
-
hydrate: false,
|
1946
|
+
target,
|
1757
1947
|
props: {
|
1758
1948
|
send: options.send,
|
1759
1949
|
publish: options.publish,
|
@@ -1788,7 +1978,8 @@ function createModal(App, options = {
|
|
1788
1978
|
},
|
1789
1979
|
},
|
1790
1980
|
};
|
1791
|
-
app =
|
1981
|
+
app = // @ts-ignore -- Svelte3 では `mount` は存在しない
|
1982
|
+
svelte.mount(App, props)
|
1792
1983
|
;
|
1793
1984
|
};
|
1794
1985
|
const handleShow = (event) => {
|
@@ -1838,7 +2029,10 @@ function createModal(App, options = {
|
|
1838
2029
|
window.addEventListener(ACTION_CHANGE_STATE_EVENT, handleState);
|
1839
2030
|
let showTriggerCleanups = [];
|
1840
2031
|
let closeTriggerCleanups = [];
|
1841
|
-
{
|
2032
|
+
if (!isOnSite()) {
|
2033
|
+
autoShow();
|
2034
|
+
}
|
2035
|
+
else {
|
1842
2036
|
showTriggerCleanups = listenShowTrigger();
|
1843
2037
|
closeTriggerCleanups = listenCloseTrigger();
|
1844
2038
|
}
|
@@ -1870,7 +2064,7 @@ function createModal(App, options = {
|
|
1870
2064
|
return appCleanup;
|
1871
2065
|
}
|
1872
2066
|
/** @internal */
|
1873
|
-
function ensureActionRoot
|
2067
|
+
function ensureActionRoot(useShadow = true) {
|
1874
2068
|
const systemConfig = getSystem();
|
1875
2069
|
const rootAttrs = {
|
1876
2070
|
class: `${KARTE_ACTION_ROOT} ${KARTE_MODAL_ROOT}`,
|
@@ -1893,73 +2087,182 @@ function ensureActionRoot$1(useShadow = true) {
|
|
1893
2087
|
return el;
|
1894
2088
|
}
|
1895
2089
|
}
|
1896
|
-
|
1897
2090
|
/**
|
1898
|
-
*
|
2091
|
+
* 非推奨
|
2092
|
+
*
|
2093
|
+
* @deprecated 非推奨
|
2094
|
+
*
|
2095
|
+
* @internal
|
1899
2096
|
*/
|
1900
|
-
|
1901
|
-
async function runScript$1(options = {
|
1902
|
-
send: () => { },
|
1903
|
-
publish: () => { },
|
1904
|
-
props: {},
|
1905
|
-
variables: {},
|
1906
|
-
localVariablesQuery: undefined,
|
1907
|
-
karteTemplate: {},
|
1908
|
-
context: { api_key: '', collection_endpoint: undefined },
|
1909
|
-
}) {
|
1910
|
-
if (!options.onCreate)
|
1911
|
-
return;
|
1912
|
-
let data = getVariables();
|
1913
|
-
initialize({ send: options.send, initialState: data.initial_state });
|
1914
|
-
initActionTable(options.localVariablesQuery);
|
1915
|
-
const { success } = await setupActionTable(options.localVariablesQuery, data, data.api_key, options.context.collection_endpoint);
|
1916
|
-
if (!success)
|
1917
|
-
return;
|
1918
|
-
// Action Tableの取得結果を反映する
|
1919
|
-
data = getVariables();
|
1920
|
-
const actionProps = {
|
1921
|
-
send: options.send,
|
1922
|
-
publish: options.publish,
|
1923
|
-
data,
|
1924
|
-
};
|
1925
|
-
options.send('script_fired');
|
1926
|
-
// 旧Widget API IFの処理
|
1927
|
-
const { onCreateHandlers } = getInternalHandlers();
|
1928
|
-
if (onCreateHandlers) {
|
1929
|
-
onCreateHandlers.forEach(h => {
|
1930
|
-
h({ send: options.send, publish: options.publish, data });
|
1931
|
-
console.debug(`${ACTION_HOOK_LABEL}: onCreate`);
|
1932
|
-
});
|
1933
|
-
}
|
1934
|
-
options.onCreate(actionProps);
|
1935
|
-
finalize();
|
1936
|
-
}
|
2097
|
+
const show = showAction;
|
1937
2098
|
/**
|
1938
|
-
*
|
2099
|
+
* 非推奨
|
1939
2100
|
*
|
1940
|
-
* @
|
2101
|
+
* @deprecated 非推奨
|
1941
2102
|
*
|
1942
|
-
* @
|
2103
|
+
* @internal
|
1943
2104
|
*/
|
1944
|
-
|
1945
|
-
return new Promise((resolve, reject) => {
|
1946
|
-
const script = document.createElement('script');
|
1947
|
-
script.src = src;
|
1948
|
-
document.body.appendChild(script);
|
1949
|
-
script.addEventListener('load', () => resolve(script));
|
1950
|
-
script.addEventListener('error', () => reject(script));
|
1951
|
-
});
|
1952
|
-
}
|
2105
|
+
const close = closeAction;
|
1953
2106
|
/**
|
1954
|
-
*
|
2107
|
+
* 非推奨
|
1955
2108
|
*
|
1956
|
-
* @
|
2109
|
+
* @deprecated 非推奨
|
1957
2110
|
*
|
1958
|
-
* @
|
2111
|
+
* @internal
|
1959
2112
|
*/
|
1960
|
-
|
1961
|
-
|
1962
|
-
|
2113
|
+
const ensureModalRoot = ensureActionRoot;
|
2114
|
+
/**
|
2115
|
+
* 非推奨
|
2116
|
+
*
|
2117
|
+
* @deprecated 非推奨
|
2118
|
+
*
|
2119
|
+
* @internal
|
2120
|
+
*/
|
2121
|
+
function createApp(App, options = {
|
2122
|
+
send: () => { },
|
2123
|
+
publish: () => { },
|
2124
|
+
props: {},
|
2125
|
+
variables: {},
|
2126
|
+
localVariablesQuery: undefined,
|
2127
|
+
context: { api_key: '' },
|
2128
|
+
}) {
|
2129
|
+
let app = null;
|
2130
|
+
const close = () => {
|
2131
|
+
if (app) {
|
2132
|
+
{
|
2133
|
+
// @ts-ignore -- Svelte3 では `unmount` は存在しない
|
2134
|
+
svelte.unmount(app);
|
2135
|
+
}
|
2136
|
+
app = null;
|
2137
|
+
}
|
2138
|
+
};
|
2139
|
+
const appArgs = {
|
2140
|
+
target: null,
|
2141
|
+
props: {
|
2142
|
+
send: options.send,
|
2143
|
+
publish: options.publish,
|
2144
|
+
close,
|
2145
|
+
data: {
|
2146
|
+
...options.props,
|
2147
|
+
...options.variables,
|
2148
|
+
},
|
2149
|
+
},
|
2150
|
+
};
|
2151
|
+
const win = ensureActionRoot(isOnSite());
|
2152
|
+
appArgs.target = win;
|
2153
|
+
return {
|
2154
|
+
close,
|
2155
|
+
show: () => {
|
2156
|
+
if (app) {
|
2157
|
+
return;
|
2158
|
+
}
|
2159
|
+
options.send('message_open');
|
2160
|
+
app = // @ts-ignore -- Svelte3 では `mount` は存在しない
|
2161
|
+
svelte.mount(App, appArgs)
|
2162
|
+
;
|
2163
|
+
},
|
2164
|
+
};
|
2165
|
+
}
|
2166
|
+
/**
|
2167
|
+
* 非推奨
|
2168
|
+
*
|
2169
|
+
* @deprecated 非推奨
|
2170
|
+
*
|
2171
|
+
* @internal
|
2172
|
+
*/
|
2173
|
+
function createFog({ color = '#000', opacity = '50%', zIndex = 999, onclick, }) {
|
2174
|
+
console.log('createFog');
|
2175
|
+
const root = ensureModalRoot();
|
2176
|
+
if (root.querySelector('.__krt-fog')) {
|
2177
|
+
return { fog: null, close: () => { } };
|
2178
|
+
}
|
2179
|
+
const fog = document.createElement('div');
|
2180
|
+
fog.className = '__krt-fog';
|
2181
|
+
Object.assign(fog.style, {
|
2182
|
+
position: 'fixed',
|
2183
|
+
left: 0,
|
2184
|
+
top: 0,
|
2185
|
+
width: '100%',
|
2186
|
+
height: '100%',
|
2187
|
+
'z-index': zIndex,
|
2188
|
+
'background-color': color,
|
2189
|
+
opacity,
|
2190
|
+
});
|
2191
|
+
const close = () => {
|
2192
|
+
onclick();
|
2193
|
+
fog.remove();
|
2194
|
+
};
|
2195
|
+
fog.onclick = close;
|
2196
|
+
root.appendChild(fog);
|
2197
|
+
return { fog, close };
|
2198
|
+
}
|
2199
|
+
|
2200
|
+
/**
|
2201
|
+
* スクリプト接客が利用するコードの管理
|
2202
|
+
*/
|
2203
|
+
/** @internal */
|
2204
|
+
async function runScript$1(options = {
|
2205
|
+
send: () => { },
|
2206
|
+
publish: () => { },
|
2207
|
+
props: {},
|
2208
|
+
variables: {},
|
2209
|
+
localVariablesQuery: undefined,
|
2210
|
+
karteTemplate: {},
|
2211
|
+
context: { api_key: '', collection_endpoint: undefined },
|
2212
|
+
}) {
|
2213
|
+
if (!options.onCreate)
|
2214
|
+
return;
|
2215
|
+
let data = getVariables();
|
2216
|
+
initialize({ send: options.send, initialState: data.initial_state });
|
2217
|
+
initActionTable(options.localVariablesQuery);
|
2218
|
+
const { success } = await setupActionTable(options.localVariablesQuery, data, data.api_key, options.context.collection_endpoint);
|
2219
|
+
if (!success)
|
2220
|
+
return;
|
2221
|
+
// Action Tableの取得結果を反映する
|
2222
|
+
data = getVariables();
|
2223
|
+
const actionProps = {
|
2224
|
+
send: options.send,
|
2225
|
+
publish: options.publish,
|
2226
|
+
data,
|
2227
|
+
};
|
2228
|
+
options.send('script_fired');
|
2229
|
+
// 旧Widget API IFの処理
|
2230
|
+
const { onCreateHandlers } = getInternalHandlers();
|
2231
|
+
if (onCreateHandlers) {
|
2232
|
+
onCreateHandlers.forEach(h => {
|
2233
|
+
h({ send: options.send, publish: options.publish, data });
|
2234
|
+
console.debug(`${ACTION_HOOK_LABEL}: onCreate`);
|
2235
|
+
});
|
2236
|
+
}
|
2237
|
+
options.onCreate(actionProps);
|
2238
|
+
finalize();
|
2239
|
+
}
|
2240
|
+
/**
|
2241
|
+
* ES Modules に対応していない JavaScript をページに読み込む
|
2242
|
+
*
|
2243
|
+
* @param src - JavaScript ファイルのリンク URL
|
2244
|
+
*
|
2245
|
+
* @public
|
2246
|
+
*/
|
2247
|
+
async function loadGlobalScript(src) {
|
2248
|
+
return new Promise((resolve, reject) => {
|
2249
|
+
const script = document.createElement('script');
|
2250
|
+
script.src = src;
|
2251
|
+
document.body.appendChild(script);
|
2252
|
+
script.addEventListener('load', () => resolve(script));
|
2253
|
+
script.addEventListener('error', () => reject(script));
|
2254
|
+
});
|
2255
|
+
}
|
2256
|
+
/**
|
2257
|
+
* グローバル CSS をページに適用する
|
2258
|
+
*
|
2259
|
+
* @param css - CSS
|
2260
|
+
*
|
2261
|
+
* @public
|
2262
|
+
*/
|
2263
|
+
async function applyGlobalCss(css) {
|
2264
|
+
return new Promise((resolve, reject) => {
|
2265
|
+
const action = document.querySelector(`.${KARTE_ACTION_ROOT}[data-${KARTE_ACTION_RID}='${actionId}']`);
|
1963
2266
|
if (!action) {
|
1964
2267
|
return;
|
1965
2268
|
}
|
@@ -2060,7 +2363,7 @@ function create(App, options) {
|
|
2060
2363
|
runScript$1(options);
|
2061
2364
|
}
|
2062
2365
|
else {
|
2063
|
-
modalCleanup = createModal(App, options);
|
2366
|
+
modalCleanup = createModal(App, options) ;
|
2064
2367
|
}
|
2065
2368
|
return () => {
|
2066
2369
|
modalCleanup();
|
@@ -2127,313 +2430,6 @@ function destroy() {
|
|
2127
2430
|
dispatchDestroyEvent();
|
2128
2431
|
}
|
2129
2432
|
|
2130
|
-
/**
|
2131
|
-
* モーダル(ポップアップ)に関連するコードの管理
|
2132
|
-
*
|
2133
|
-
* アクションのShow, Close, ChangeStateの状態はここで管理する。
|
2134
|
-
*/
|
2135
|
-
/**
|
2136
|
-
* アクションが表示 (show) された後にフックする関数
|
2137
|
-
*
|
2138
|
-
* @param fn - 呼び出されるフック関数
|
2139
|
-
*
|
2140
|
-
* @public
|
2141
|
-
*/
|
2142
|
-
function onShow(fn) {
|
2143
|
-
let { onShowHandlers } = getInternalHandlers();
|
2144
|
-
if (!onShowHandlers) {
|
2145
|
-
onShowHandlers = [];
|
2146
|
-
}
|
2147
|
-
onShowHandlers.push(fn);
|
2148
|
-
setInternalHandlers({ onShowHandlers });
|
2149
|
-
}
|
2150
|
-
/**
|
2151
|
-
* アクションがクローズ (close) される前にフックする関数
|
2152
|
-
*
|
2153
|
-
* @param fn - 呼び出されるフック関数
|
2154
|
-
*
|
2155
|
-
* @public
|
2156
|
-
*/
|
2157
|
-
function onClose(fn) {
|
2158
|
-
let { onCloseHandlers } = getInternalHandlers();
|
2159
|
-
if (!onCloseHandlers) {
|
2160
|
-
onCloseHandlers = [];
|
2161
|
-
}
|
2162
|
-
onCloseHandlers.push(fn);
|
2163
|
-
setInternalHandlers({ onCloseHandlers });
|
2164
|
-
}
|
2165
|
-
/**
|
2166
|
-
* アクションのステートが変更された (changeState) 後にフックする関数
|
2167
|
-
*
|
2168
|
-
* @param fn - 呼び出されるフック関数
|
2169
|
-
*
|
2170
|
-
* @public
|
2171
|
-
*/
|
2172
|
-
function onChangeState(fn) {
|
2173
|
-
let { onChangeStateHandlers } = getInternalHandlers();
|
2174
|
-
if (!onChangeStateHandlers) {
|
2175
|
-
onChangeStateHandlers = [];
|
2176
|
-
}
|
2177
|
-
onChangeStateHandlers.push(fn);
|
2178
|
-
setInternalHandlers({ onChangeStateHandlers });
|
2179
|
-
}
|
2180
|
-
/**
|
2181
|
-
* アクションを表示する
|
2182
|
-
*
|
2183
|
-
* @public
|
2184
|
-
*/
|
2185
|
-
function showAction() {
|
2186
|
-
const event = new CustomEvent(ACTION_SHOW_EVENT, { detail: { trigger: 'custom' } });
|
2187
|
-
window.dispatchEvent(event);
|
2188
|
-
}
|
2189
|
-
/**
|
2190
|
-
* アクションを閉じる
|
2191
|
-
*
|
2192
|
-
* @param trigger - 閉じた時のトリガー。デフォルト `'none'`
|
2193
|
-
*
|
2194
|
-
* @public
|
2195
|
-
*/
|
2196
|
-
function closeAction(trigger = 'none') {
|
2197
|
-
const event = new CustomEvent(ACTION_CLOSE_EVENT, { detail: { trigger } });
|
2198
|
-
window.dispatchEvent(event);
|
2199
|
-
}
|
2200
|
-
/**
|
2201
|
-
* アクションに CSS を適用する
|
2202
|
-
*
|
2203
|
-
* @param css - 適用する CSS
|
2204
|
-
*
|
2205
|
-
* @returns 適用された style 要素を返す Promise
|
2206
|
-
*
|
2207
|
-
* @public
|
2208
|
-
*/
|
2209
|
-
async function applyCss(css) {
|
2210
|
-
return new Promise((resolve, reject) => {
|
2211
|
-
const style = document.createElement('style');
|
2212
|
-
style.textContent = css;
|
2213
|
-
const shadowRoot = getActionRoot();
|
2214
|
-
if (!shadowRoot)
|
2215
|
-
return;
|
2216
|
-
shadowRoot.append(style);
|
2217
|
-
style.addEventListener('load', () => resolve(style));
|
2218
|
-
style.addEventListener('error', () => reject(style));
|
2219
|
-
});
|
2220
|
-
}
|
2221
|
-
async function fixFontFaceIssue(href, cssRules) {
|
2222
|
-
const css = new CSSStyleSheet();
|
2223
|
-
// @ts-ignore
|
2224
|
-
await css.replace(cssRules);
|
2225
|
-
const rules = [];
|
2226
|
-
const fixedRules = [];
|
2227
|
-
Array.from(css.cssRules).forEach(cssRule => {
|
2228
|
-
if (cssRule.type !== 5) {
|
2229
|
-
rules.push(cssRule.cssText);
|
2230
|
-
}
|
2231
|
-
// type 5 is @font-face
|
2232
|
-
const split = href.split('/');
|
2233
|
-
const stylePath = split.slice(0, split.length - 1).join('/');
|
2234
|
-
const cssText = cssRule.cssText;
|
2235
|
-
const newCssText = cssText.replace(
|
2236
|
-
// relative paths
|
2237
|
-
/url\s*\(\s*['"]?(?!((\/)|((?:https?:)?\/\/)|(?:data:?:)))([^'")]+)['"]?\s*\)/g, `url("${stylePath}/$4")`);
|
2238
|
-
if (cssText === newCssText)
|
2239
|
-
return;
|
2240
|
-
fixedRules.push(newCssText);
|
2241
|
-
});
|
2242
|
-
return [rules.join('\n'), fixedRules.join('\n')];
|
2243
|
-
}
|
2244
|
-
/**
|
2245
|
-
* アクションにグローバルなスタイルを読み込む
|
2246
|
-
*
|
2247
|
-
* @param href - style ファイルのリンク URL
|
2248
|
-
*
|
2249
|
-
* @public
|
2250
|
-
*/
|
2251
|
-
async function loadStyle(href) {
|
2252
|
-
const sr = getActionRoot();
|
2253
|
-
if (!sr)
|
2254
|
-
return;
|
2255
|
-
let cssRules = '';
|
2256
|
-
try {
|
2257
|
-
const res = await fetch(href);
|
2258
|
-
cssRules = await res.text();
|
2259
|
-
}
|
2260
|
-
catch (_) {
|
2261
|
-
// pass
|
2262
|
-
}
|
2263
|
-
if (!cssRules)
|
2264
|
-
return;
|
2265
|
-
// Chromeのバグで、Shadow Rootの@font-faceを絶対パスで指定する必要がある
|
2266
|
-
// @see https://stackoverflow.com/a/63717709
|
2267
|
-
const [rules, fontFaceRules] = await fixFontFaceIssue(href, cssRules);
|
2268
|
-
const css = new CSSStyleSheet();
|
2269
|
-
// @ts-ignore
|
2270
|
-
await css.replace(rules);
|
2271
|
-
const fontFaceCss = new CSSStyleSheet();
|
2272
|
-
// @ts-ignore
|
2273
|
-
await fontFaceCss.replace(fontFaceRules);
|
2274
|
-
// @ts-ignore
|
2275
|
-
sr.adoptedStyleSheets = [...sr.adoptedStyleSheets, css, fontFaceCss];
|
2276
|
-
// Chromeのバグで、ページとShadow Rootの両方に、@font-faceを設定する必要がある
|
2277
|
-
// @see https://stackoverflow.com/a/63717709
|
2278
|
-
// @ts-ignore
|
2279
|
-
document.adoptedStyleSheets = [...document.adoptedStyleSheets, css, fontFaceCss];
|
2280
|
-
}
|
2281
|
-
// @internal
|
2282
|
-
function getCssVariables(data) {
|
2283
|
-
return Object.entries(data)
|
2284
|
-
.filter(([key, value]) => {
|
2285
|
-
return ['string', 'number'].includes(typeof value) && key.startsWith('--');
|
2286
|
-
})
|
2287
|
-
.map(([key, value]) => `${key}:${value}`)
|
2288
|
-
.join(';');
|
2289
|
-
}
|
2290
|
-
/**
|
2291
|
-
* アクションのルートの DOM 要素を取得する
|
2292
|
-
*
|
2293
|
-
* @returns アクションがルートの DOM 要素 を持つ場合は DOM 要素を返します。ない場合は `null` を返します
|
2294
|
-
*
|
2295
|
-
* @public
|
2296
|
-
*/
|
2297
|
-
function getActionRoot() {
|
2298
|
-
const root = document.querySelector(`.${KARTE_ACTION_ROOT}[data-${KARTE_ACTION_RID}='${actionId}']`);
|
2299
|
-
if (!root?.shadowRoot) {
|
2300
|
-
return null;
|
2301
|
-
}
|
2302
|
-
return root.shadowRoot;
|
2303
|
-
}
|
2304
|
-
/** @internal */
|
2305
|
-
function ensureActionRoot() {
|
2306
|
-
const systemConfig = getSystem();
|
2307
|
-
const rootAttrs = {
|
2308
|
-
class: `${KARTE_ACTION_ROOT} ${KARTE_MODAL_ROOT}`,
|
2309
|
-
[`data-${KARTE_ACTION_RID}`]: actionId,
|
2310
|
-
[`data-${KARTE_ACTION_SHORTEN_ID}`]: systemConfig.shortenId
|
2311
|
-
? systemConfig.shortenId
|
2312
|
-
: ALL_ACTION_SHORTEN_ID,
|
2313
|
-
style: { display: 'block' },
|
2314
|
-
};
|
2315
|
-
let el = document.querySelector(`.${KARTE_MODAL_ROOT}[data-${KARTE_ACTION_RID}='${actionId}']`);
|
2316
|
-
if (el == null) {
|
2317
|
-
el = h('div', rootAttrs);
|
2318
|
-
document.body.appendChild(el);
|
2319
|
-
}
|
2320
|
-
const isShadow = !!document.body.attachShadow;
|
2321
|
-
if (isShadow) {
|
2322
|
-
return el.shadowRoot ?? el.attachShadow({ mode: 'open' });
|
2323
|
-
}
|
2324
|
-
else {
|
2325
|
-
return el;
|
2326
|
-
}
|
2327
|
-
}
|
2328
|
-
/**
|
2329
|
-
* 非推奨
|
2330
|
-
*
|
2331
|
-
* @deprecated 非推奨
|
2332
|
-
*
|
2333
|
-
* @internal
|
2334
|
-
*/
|
2335
|
-
const show = showAction;
|
2336
|
-
/**
|
2337
|
-
* 非推奨
|
2338
|
-
*
|
2339
|
-
* @deprecated 非推奨
|
2340
|
-
*
|
2341
|
-
* @internal
|
2342
|
-
*/
|
2343
|
-
const close = closeAction;
|
2344
|
-
/**
|
2345
|
-
* 非推奨
|
2346
|
-
*
|
2347
|
-
* @deprecated 非推奨
|
2348
|
-
*
|
2349
|
-
* @internal
|
2350
|
-
*/
|
2351
|
-
const ensureModalRoot = ensureActionRoot;
|
2352
|
-
/**
|
2353
|
-
* 非推奨
|
2354
|
-
*
|
2355
|
-
* @deprecated 非推奨
|
2356
|
-
*
|
2357
|
-
* @internal
|
2358
|
-
*/
|
2359
|
-
function createApp(App, options = {
|
2360
|
-
send: () => { },
|
2361
|
-
publish: () => { },
|
2362
|
-
props: {},
|
2363
|
-
variables: {},
|
2364
|
-
localVariablesQuery: undefined,
|
2365
|
-
context: { api_key: '' },
|
2366
|
-
}) {
|
2367
|
-
let app = null;
|
2368
|
-
const close = () => {
|
2369
|
-
if (app) {
|
2370
|
-
{
|
2371
|
-
// @ts-ignore -- Svelte3 では `unmount` は存在しない
|
2372
|
-
svelte.unmount(app);
|
2373
|
-
}
|
2374
|
-
app = null;
|
2375
|
-
}
|
2376
|
-
};
|
2377
|
-
const appArgs = {
|
2378
|
-
target: null,
|
2379
|
-
props: {
|
2380
|
-
send: options.send,
|
2381
|
-
publish: options.publish,
|
2382
|
-
close,
|
2383
|
-
data: {
|
2384
|
-
...options.props,
|
2385
|
-
...options.variables,
|
2386
|
-
},
|
2387
|
-
},
|
2388
|
-
};
|
2389
|
-
const win = ensureModalRoot();
|
2390
|
-
appArgs.target = win;
|
2391
|
-
return {
|
2392
|
-
close,
|
2393
|
-
show: () => {
|
2394
|
-
if (app) {
|
2395
|
-
return;
|
2396
|
-
}
|
2397
|
-
options.send('message_open');
|
2398
|
-
app = // @ts-ignore -- Svelte3 では `mount` は存在しない
|
2399
|
-
svelte.mount(App, appArgs)
|
2400
|
-
;
|
2401
|
-
},
|
2402
|
-
};
|
2403
|
-
}
|
2404
|
-
/**
|
2405
|
-
* 非推奨
|
2406
|
-
*
|
2407
|
-
* @deprecated 非推奨
|
2408
|
-
*
|
2409
|
-
* @internal
|
2410
|
-
*/
|
2411
|
-
function createFog({ color = '#000', opacity = '50%', zIndex = 999, onclick, }) {
|
2412
|
-
const root = ensureModalRoot();
|
2413
|
-
if (root.querySelector('.__krt-fog')) {
|
2414
|
-
return { fog: null, close: () => { } };
|
2415
|
-
}
|
2416
|
-
const fog = document.createElement('div');
|
2417
|
-
fog.className = '__krt-fog';
|
2418
|
-
Object.assign(fog.style, {
|
2419
|
-
position: 'fixed',
|
2420
|
-
left: 0,
|
2421
|
-
top: 0,
|
2422
|
-
width: '100%',
|
2423
|
-
height: '100%',
|
2424
|
-
'z-index': zIndex,
|
2425
|
-
'background-color': color,
|
2426
|
-
opacity,
|
2427
|
-
});
|
2428
|
-
const close = () => {
|
2429
|
-
onclick();
|
2430
|
-
fog.remove();
|
2431
|
-
};
|
2432
|
-
fog.onclick = close;
|
2433
|
-
root.appendChild(fog);
|
2434
|
-
return { fog, close };
|
2435
|
-
}
|
2436
|
-
|
2437
2433
|
const USER_ID_VARIABLE_NAME = '__karte_form_identify_user_id';
|
2438
2434
|
const MAX_LENGTH_FREE_ANSWER = 2000;
|
2439
2435
|
function createAnswerValue(value) {
|
@@ -2906,7 +2902,10 @@ function Header($$anchor, $$props) {
|
|
2906
2902
|
$fonts()
|
2907
2903
|
),
|
2908
2904
|
() => {
|
2909
|
-
if (
|
2905
|
+
if (isPreview()) {
|
2906
|
+
// フォントのロードが遅れてエディタのプレビューがガタつく対策
|
2907
|
+
$.set(googleFontUrl, makeGoogleFontUrl(Fonts.filter((font) => font !== SYSTEM_FONT)));
|
2908
|
+
} else if ($fonts().length > 0) {
|
2910
2909
|
$.set(googleFontUrl, makeGoogleFontUrl($fonts()));
|
2911
2910
|
}
|
2912
2911
|
}
|
@@ -3477,6 +3476,9 @@ const EASING = {
|
|
3477
3476
|
* @internal
|
3478
3477
|
*/
|
3479
3478
|
function customAnimation(node, { transforms, animationStyle, delay = 0, duration = 1000 }) {
|
3479
|
+
if (!isOnSite()) {
|
3480
|
+
return {};
|
3481
|
+
}
|
3480
3482
|
let [x, y] = [0, 0];
|
3481
3483
|
for (const { query, x: tx, y: ty } of transforms) {
|
3482
3484
|
if (query == null || window.matchMedia(query).matches) {
|
@@ -6357,7 +6359,6 @@ function Modal($$anchor, $$props) {
|
|
6357
6359
|
let closeEventValue = $.prop($$props, 'closeEventValue', 8, null);
|
6358
6360
|
let layerId = $.prop($$props, 'layerId', 8, '');
|
6359
6361
|
const { brandKit } = useBrandKit();
|
6360
|
-
const isCanvasPreview = (document.querySelector('#preview')?.getAttribute('data-canvas-preview') ?? 'false') === 'true';
|
6361
6362
|
// モーダル背景の設定
|
6362
6363
|
const isExistBackgroundOverlayValue = placement() && placement().backgroundOverlay !== undefined;
|
6363
6364
|
let backgroundOverlay = $.mutable_state(DefaultModalPlacement.backgroundOverlay);
|
@@ -6403,7 +6404,7 @@ function Modal($$anchor, $$props) {
|
|
6403
6404
|
$.deep_read_state(breakPoint())
|
6404
6405
|
),
|
6405
6406
|
() => {
|
6406
|
-
if (!isCanvasPreview && isExistBackgroundOverlayValue) {
|
6407
|
+
if (!isCanvasPreview() && isExistBackgroundOverlayValue) {
|
6407
6408
|
$.set(backgroundOverlay, placement().backgroundOverlay);
|
6408
6409
|
}
|
6409
6410
|
|
@@ -6509,7 +6510,7 @@ function Modal($$anchor, $$props) {
|
|
6509
6510
|
// 表示位置のスタイルの設定
|
6510
6511
|
let position = DefaultModalPlacement.position;
|
6511
6512
|
|
6512
|
-
if (!isCanvasPreview && placement() && placement().position !== null) {
|
6513
|
+
if (!isCanvasPreview() && placement() && placement().position !== null) {
|
6513
6514
|
position = placement().position;
|
6514
6515
|
}
|
6515
6516
|
|
@@ -6526,7 +6527,7 @@ function Modal($$anchor, $$props) {
|
|
6526
6527
|
$.set(transforms, []);
|
6527
6528
|
|
6528
6529
|
DEVICE_IDS.forEach((deviceId) => {
|
6529
|
-
if (!isCanvasPreview && useBreakPoint()) {
|
6530
|
+
if (!isCanvasPreview() && useBreakPoint()) {
|
6530
6531
|
const positionWithBp = breakPoint()[deviceId]?.placement?.position;
|
6531
6532
|
|
6532
6533
|
$.get(transforms).push({
|
@@ -6562,7 +6563,7 @@ function Modal($$anchor, $$props) {
|
|
6562
6563
|
() => {
|
6563
6564
|
let margin = DefaultModalPlacement.margin;
|
6564
6565
|
|
6565
|
-
if (!isCanvasPreview && placement() && placement().margin !== null) {
|
6566
|
+
if (!isCanvasPreview() && placement() && placement().margin !== null) {
|
6566
6567
|
margin = placement().margin;
|
6567
6568
|
}
|
6568
6569
|
|
@@ -6573,7 +6574,7 @@ function Modal($$anchor, $$props) {
|
|
6573
6574
|
}
|
6574
6575
|
|
6575
6576
|
DEVICE_IDS.forEach((deviceId) => {
|
6576
|
-
if (!isCanvasPreview && useBreakPoint()) {
|
6577
|
+
if (!isCanvasPreview() && useBreakPoint()) {
|
6577
6578
|
const marginWithBp = breakPoint()[deviceId]?.placement?.margin;
|
6578
6579
|
|
6579
6580
|
marginStyle = getMarginStyle(marginWithBp);
|
@@ -6687,7 +6688,7 @@ function Modal($$anchor, $$props) {
|
|
6687
6688
|
};
|
6688
6689
|
|
6689
6690
|
$.if(node, ($$render) => {
|
6690
|
-
if (isCanvasPreview) $$render(consequent); else $$render(alternate, false);
|
6691
|
+
if (isCanvasPreview()) $$render(consequent); else $$render(alternate, false);
|
6691
6692
|
});
|
6692
6693
|
}
|
6693
6694
|
|