@plaidev/karte-action-sdk 1.1.221 → 1.1.223

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.
@@ -192,25 +192,19 @@ type ActionTableQueryParams = {
192
192
  /**
193
193
  * アクションテーブルの設定情報
194
194
  *
195
- * @public
195
+ * @param api_key - API Key
196
+ * @param table - テーブル名
197
+ * @param endpoint - エンドポイント / 指定がない場合はデフォルトのエンドポイントを使用します。検証用途以外での通常利用では指定なしで大丈夫です。
196
198
  */
197
199
  type CollectionConfig = {
198
- /**
199
- * APIキー
200
- */
201
200
  api_key: string;
202
- /**
203
- * テーブル名
204
- */
205
201
  table: string;
206
- /**
207
- * エンドポイント
208
- */ endpoint?: string;
202
+ endpoint?: string;
209
203
  };
210
204
  /**
211
205
  * アクションテーブルを管理するメソッドを取得する
212
206
  *
213
- * @param config - 設定情報
207
+ * @param config - アクションテーブル設定情報
214
208
  *
215
209
  * @returns メソッドを返します
216
210
  *
@@ -1515,6 +1509,75 @@ declare function createFog({ color, opacity, zIndex, onclick }: {
1515
1509
  fog: HTMLDivElement;
1516
1510
  close: () => void;
1517
1511
  };
1512
+ type AnswerValue = {
1513
+ choices: string[];
1514
+ } | {
1515
+ free_answer: string;
1516
+ };
1517
+ /**
1518
+ * 選択式のアンケート回答を追加する
1519
+ *
1520
+ * @param questionId - 質問ID
1521
+ * @param choices - 回答内容
1522
+ *
1523
+ * @public
1524
+ */
1525
+ declare function addChoiceAnswer(questionId: string, choices: string[], validation?: {
1526
+ isValid: boolean;
1527
+ statePath: string;
1528
+ }): void;
1529
+ /**
1530
+ * 自由記述式のアンケート回答を追加する
1531
+ *
1532
+ * @param questionId - 質問ID
1533
+ * @param freeAnswer - 回答内容
1534
+ *
1535
+ * @public
1536
+ */
1537
+ declare function addFreeAnswer(questionId: string, freeAnswer: string, validation?: {
1538
+ isValid: boolean;
1539
+ statePath: string;
1540
+ }): void;
1541
+ /**
1542
+ * 回答済の回答を削除
1543
+ *
1544
+ * @param questionId - 質問ID
1545
+ *
1546
+ * @public
1547
+ */
1548
+ declare function removeAnswer(questionId: string): void;
1549
+ /**
1550
+ * 回答済の回答内容を取得する
1551
+ *
1552
+ * @param questionId - 質問ID
1553
+ *
1554
+ * @returns 回答データ
1555
+ *
1556
+ * @public
1557
+ */
1558
+ declare function getAnsweredQuestion(questionId: string): AnswerValue | undefined;
1559
+ /**
1560
+ * 回答済の回答IDのリストを取得
1561
+ *
1562
+ * @returns 回答済の質問の質問IDの配列
1563
+ *
1564
+ * @public
1565
+ */
1566
+ declare function getAnsweredQuestionIds(): string[];
1567
+ /**
1568
+ * `sendAnswers`のエイリアス
1569
+ *
1570
+ * @public
1571
+ */
1572
+ declare function sendAnswer(): boolean;
1573
+ /**
1574
+ * 回答済の回答をまとめてイベントとして送信する
1575
+ *
1576
+ * @returns イベント送信の成功/失敗
1577
+ *
1578
+ * @public
1579
+ */
1580
+ declare function sendAnswers(): boolean;
1518
1581
  declare namespace widget {
1519
1582
  /**
1520
1583
  * アクションの汎用的なタイプを定義する
@@ -1692,25 +1755,19 @@ declare namespace widget {
1692
1755
  /**
1693
1756
  * アクションテーブルの設定情報
1694
1757
  *
1695
- * @public
1758
+ * @param api_key - API Key
1759
+ * @param table - テーブル名
1760
+ * @param endpoint - エンドポイント / 指定がない場合はデフォルトのエンドポイントを使用します。検証用途以外での通常利用では指定なしで大丈夫です。
1696
1761
  */
1697
1762
  type CollectionConfig = {
1698
- /**
1699
- * APIキー
1700
- */
1701
1763
  api_key: string;
1702
- /**
1703
- * テーブル名
1704
- */
1705
1764
  table: string;
1706
- /**
1707
- * エンドポイント
1708
- */ endpoint?: string;
1765
+ endpoint?: string;
1709
1766
  };
1710
1767
  /**
1711
1768
  * アクションテーブルを管理するメソッドを取得する
1712
1769
  *
1713
- * @param config - 設定情報
1770
+ * @param config - アクションテーブル設定情報
1714
1771
  *
1715
1772
  * @returns メソッドを返します
1716
1773
  *
@@ -2277,7 +2334,7 @@ declare const afterUpdate: typeof afterUpdateSvelte;
2277
2334
  declare const tick: typeof tickSvelte;
2278
2335
  // @internal
2279
2336
  declare const LAYOUT_COMPONENT_NAMES: string[];
2280
- export { ACTION_HOOK_LABEL, KARTE_MODAL_ROOT, create, destroyAction, onCreate, onDestroy, showModal, destroy, initialize, finalize, loadGlobalScript, loadGlobalStyle, applyGlobalCss, getState, setState, getStates, isOpened, getVariables, setVariables, resetVariables, getEventHandlers, setEventHandlers, resetEventHandlers, getSystem, setSetting, eventHandlers, variables, formData, state, onScroll, onTime, getLogs, getEvents, logger, listenLogger, hideOnScroll, hideOnTime, showOnScroll, showOnTime, PropTypes, PropType, Code, MediaQueries, MediaQuery, Directions, Direction, AnimationStyles, AnimationStyle, ModalPositions, ModalPosition, ModalMargin, ModalPlacement, DefaultModalPlacement, Elasticities, Elasticity, ElasticityStyle, DefaultElasticity, TextDirections, TextDirection, OperationArgumentType, Operation, OnClickOperationOptions, OnClickOperation, LongText, Url, RegExpProp, Image, LengthUnits, LengthUnit, Length, Color, FontWeight, SYSTEM_FONT, Fonts, Font, Justifies, Justify, Alignments, Alignment, FlexDirections, FlexDirection, ObjectFits, ObjectFit, ClipPaths, ClipPath, Repeats, Repeat, BackgroundSizes, BackgroundSize, Cursors, Cursor, Overflows, Overflow, Border, BorderStyle, BorderWidth, BoxShadow, Style, TransitState, WritingModes, WritingMode, DateTime, Icon, ListSeparatorTypes, EdgePosition, DefaultEdgePosition, ListSeparatorNone, ListSeparatorBorder, ListSeparatorGap, ListSeparator, DefaultListSeparatorNone, DefaultListSeparatorBorder, DefaultListSeparatorGap, DefaultListSeparator, ListBackgroundTypes, ListBackgroundNone, ListBackgroundStripe, ListBackground, DefaultListBackgroundNone, DefaultListBackgroundStripe, DefaultListBackground, ListDirections, ListDirection, ListContext, SlideButtonIcon, SlideButtonText, SlideButton, DefaultSlideButton, SlideButtonPosition, SlideNavigationButton, DefaultSlideNavigationButton, FormInputName, FormButtonColor, DefaultFormButtonColor, ModalStyle, ModalBreakPoint, DefaultModalBreakPoint, FormIdentifyTextFields, FormIdentifyTextField, FormIdentifyTextFieldValidations, FormIdentifyTextFieldPlaceholders, DefaultFormIdentifyTextField, FormIdentifyBooleanFields, FormIdentifyBooleanField, DefaultFormIdentifyBooleanField, showAction, closeAction, loadStyle, applyCss, onShow, onClose, onChangeState, getActionRoot, getCssVariables, show, close, ensureModalRoot, createApp, createFog, collection, loadActionTableRow, loadActionTableRows, loadActionTableQuery, loadActionTable, widget, onMount, onDestory, beforeUpdate, afterUpdate, tick, LAYOUT_COMPONENT_NAMES };
2337
+ export { ACTION_HOOK_LABEL, KARTE_MODAL_ROOT, create, destroyAction, onCreate, onDestroy, showModal, destroy, initialize, finalize, loadGlobalScript, loadGlobalStyle, applyGlobalCss, getState, setState, getStates, isOpened, getVariables, setVariables, resetVariables, getEventHandlers, setEventHandlers, resetEventHandlers, getSystem, setSetting, eventHandlers, variables, formData, state, onScroll, onTime, getLogs, getEvents, logger, listenLogger, hideOnScroll, hideOnTime, showOnScroll, showOnTime, PropTypes, PropType, Code, MediaQueries, MediaQuery, Directions, Direction, AnimationStyles, AnimationStyle, ModalPositions, ModalPosition, ModalMargin, ModalPlacement, DefaultModalPlacement, Elasticities, Elasticity, ElasticityStyle, DefaultElasticity, TextDirections, TextDirection, OperationArgumentType, Operation, OnClickOperationOptions, OnClickOperation, LongText, Url, RegExpProp, Image, LengthUnits, LengthUnit, Length, Color, FontWeight, SYSTEM_FONT, Fonts, Font, Justifies, Justify, Alignments, Alignment, FlexDirections, FlexDirection, ObjectFits, ObjectFit, ClipPaths, ClipPath, Repeats, Repeat, BackgroundSizes, BackgroundSize, Cursors, Cursor, Overflows, Overflow, Border, BorderStyle, BorderWidth, BoxShadow, Style, TransitState, WritingModes, WritingMode, DateTime, Icon, ListSeparatorTypes, EdgePosition, DefaultEdgePosition, ListSeparatorNone, ListSeparatorBorder, ListSeparatorGap, ListSeparator, DefaultListSeparatorNone, DefaultListSeparatorBorder, DefaultListSeparatorGap, DefaultListSeparator, ListBackgroundTypes, ListBackgroundNone, ListBackgroundStripe, ListBackground, DefaultListBackgroundNone, DefaultListBackgroundStripe, DefaultListBackground, ListDirections, ListDirection, ListContext, SlideButtonIcon, SlideButtonText, SlideButton, DefaultSlideButton, SlideButtonPosition, SlideNavigationButton, DefaultSlideNavigationButton, FormInputName, FormButtonColor, DefaultFormButtonColor, ModalStyle, ModalBreakPoint, DefaultModalBreakPoint, FormIdentifyTextFields, FormIdentifyTextField, FormIdentifyTextFieldValidations, FormIdentifyTextFieldPlaceholders, DefaultFormIdentifyTextField, FormIdentifyBooleanFields, FormIdentifyBooleanField, DefaultFormIdentifyBooleanField, showAction, closeAction, loadStyle, applyCss, onShow, onClose, onChangeState, getActionRoot, getCssVariables, show, close, ensureModalRoot, createApp, createFog, collection, loadActionTableRow, loadActionTableRows, loadActionTableQuery, loadActionTable, addChoiceAnswer, addFreeAnswer, removeAnswer, getAnsweredQuestion, getAnsweredQuestionIds, sendAnswer, sendAnswers, widget, onMount, onDestory, beforeUpdate, afterUpdate, tick, LAYOUT_COMPONENT_NAMES };
2281
2338
  export type { SystemConfig, ActionVariables, ActionEventHandler, ActionProps, ActionOptions, ActionHook, ActionHookLog, ActionChangeStateHook, SendFunction, PublishFunction, OnScrollContext, OnScrollFunction, ScrollDirection, LogLevel, Log, Event, ActionCloseHook, ShowTrigger, CloseTrigger, CollectionConfig, ActionTableRowRequestConfig, ActionTableRowsRequestConfig, ActionTableQueryRequestConfig, ActionTableRequestConfig };
2282
2339
  export { default as State } from './components/State.svelte';
2283
2340
  export { default as StateItem } from './components/StateItem.svelte';
@@ -1338,7 +1338,7 @@ const DEFAULT_COLLECTION_ENDPOINT = typeof __FLYER_GEN_COLLECTION_API_ENDPOINT__
1338
1338
  /**
1339
1339
  * アクションテーブルを管理するメソッドを取得する
1340
1340
  *
1341
- * @param config - 設定情報
1341
+ * @param config - アクションテーブル設定情報
1342
1342
  *
1343
1343
  * @returns メソッドを返します
1344
1344
  *
@@ -1349,6 +1349,14 @@ function collection$1(config) {
1349
1349
  const api_key = config.api_key;
1350
1350
  const table = config.table;
1351
1351
  return {
1352
+ /**
1353
+ * キーを1つ、または複数指定して、対応するアクションテーブルの行を取得する
1354
+ *
1355
+ * @param key - 取得する行のキーを一つ、または複数配列で指定
1356
+ * @param cb - テーブルの行を取得した後に実行するcallback関数
1357
+ *
1358
+ * @public
1359
+ */
1352
1360
  get(key, cb) {
1353
1361
  if (Array.isArray(key)) {
1354
1362
  return request(`${endpoint}/getByKeys`, {
@@ -1358,15 +1366,25 @@ function collection$1(config) {
1358
1366
  }, cb);
1359
1367
  }
1360
1368
  else {
1361
- request(`${endpoint}/getByKey`, {
1369
+ return request(`${endpoint}/getByKey`, {
1362
1370
  api_key,
1363
1371
  name: table,
1364
1372
  key,
1365
1373
  }, cb);
1366
1374
  }
1367
1375
  },
1376
+ /**
1377
+ * クエリーを指定して、アクションテーブルから行を取得する
1378
+ * なお、クエリーは事前に管理画面で設定しておく必要があります。
1379
+ *
1380
+ * @param query_name - クエリー名
1381
+ * @param params - クエリーに指定するパラメーター。 `{key: value}` の形式で指定
1382
+ * @param cb - テーブルの行を取得した後に実行するcallback関数
1383
+ *
1384
+ * @public
1385
+ */
1368
1386
  getByQuery(query_name, params, options, cb) {
1369
- request(`${endpoint}/getByQuery`, {
1387
+ return request(`${endpoint}/getByQuery`, {
1370
1388
  api_key,
1371
1389
  name: table,
1372
1390
  query_name,
@@ -1374,6 +1392,7 @@ function collection$1(config) {
1374
1392
  options,
1375
1393
  }, cb);
1376
1394
  },
1395
+ /** @internal */
1377
1396
  set(key, value, cb) {
1378
1397
  request(`${endpoint}/set`, {
1379
1398
  api_key,
@@ -2255,6 +2274,247 @@ function destroy() {
2255
2274
  dispatchDestroyEvent();
2256
2275
  }
2257
2276
 
2277
+ const USER_ID_VARIABLE_NAME = '__karte_form_identify_user_id';
2278
+ const MAX_LENGTH_FREE_ANSWER = 2000;
2279
+ function isEmpty(value) {
2280
+ if (Array.isArray(value)) {
2281
+ return value.length === 0;
2282
+ }
2283
+ else {
2284
+ return !value;
2285
+ }
2286
+ }
2287
+ /** @internal */
2288
+ function createInputRegisterer(formData) {
2289
+ const registerInput = ({ name, statePath, validator = () => true, initialValue, }) => {
2290
+ const writableValue = {
2291
+ subscribe(run) {
2292
+ return formData.subscribe(formData => {
2293
+ run(formData[name]?.value);
2294
+ });
2295
+ },
2296
+ set(value) {
2297
+ formData.update(prev => ({
2298
+ ...prev,
2299
+ [name]: {
2300
+ statePath,
2301
+ value,
2302
+ isValid: validator(value),
2303
+ },
2304
+ }));
2305
+ },
2306
+ update(updater) {
2307
+ formData.update(prev => {
2308
+ const prevValue = prev[name]?.value;
2309
+ if (prevValue === undefined)
2310
+ return prev;
2311
+ const value = updater(prevValue);
2312
+ return {
2313
+ ...prev,
2314
+ [name]: {
2315
+ statePath,
2316
+ value,
2317
+ isValid: validator(value),
2318
+ },
2319
+ };
2320
+ });
2321
+ },
2322
+ };
2323
+ const readableIsValid = {
2324
+ subscribe(run) {
2325
+ return formData.subscribe(formData => {
2326
+ run(formData[name]?.isValid);
2327
+ });
2328
+ },
2329
+ };
2330
+ if (isEmpty(get(writableValue))) {
2331
+ writableValue.set(initialValue);
2332
+ }
2333
+ return {
2334
+ value: writableValue,
2335
+ isValid: readableIsValid,
2336
+ };
2337
+ };
2338
+ return registerInput;
2339
+ }
2340
+ /** @internal */
2341
+ const registerInput = createInputRegisterer(formData);
2342
+ /** @internal */
2343
+ const registerIdentifyInput = createInputRegisterer(identifyFormData);
2344
+ function validateFormData(formData, statePath) {
2345
+ return Object.entries(formData)
2346
+ .filter(([_, { statePath: s }]) => s === statePath) // eslint-disable-line @typescript-eslint/no-unused-vars
2347
+ .every(([_, { isValid }]) => isValid); // eslint-disable-line @typescript-eslint/no-unused-vars
2348
+ }
2349
+ /** @internal */
2350
+ const getValuesAreValidReadable = statePath => ({
2351
+ subscribe(callback) {
2352
+ return formData.subscribe(formData => identifyFormData.subscribe(identifyFormData => {
2353
+ const valuesAreValid = validateFormData(formData, statePath) && validateFormData(identifyFormData, statePath);
2354
+ callback(valuesAreValid);
2355
+ }));
2356
+ },
2357
+ });
2358
+ function createAnswerValue(value) {
2359
+ if (Array.isArray(value)) {
2360
+ return {
2361
+ choices: value,
2362
+ };
2363
+ }
2364
+ else if (typeof value === 'string') {
2365
+ return {
2366
+ free_answer: value,
2367
+ };
2368
+ }
2369
+ }
2370
+ function formDataToEventValues(campaignId, formData) {
2371
+ const questions = [];
2372
+ const answersMap = {};
2373
+ Object.entries(formData).forEach(([name, dataItem]) => {
2374
+ questions.push(name);
2375
+ const value = dataItem.value;
2376
+ const answerKey = `question_${name}`;
2377
+ const answerValue = createAnswerValue(value);
2378
+ answersMap[answerKey] = answerValue;
2379
+ });
2380
+ return {
2381
+ [campaignId]: {
2382
+ questions,
2383
+ ...answersMap,
2384
+ },
2385
+ };
2386
+ }
2387
+ function formDataToIdentifyEventValues(formData) {
2388
+ return Object.fromEntries(Object.entries(formData).map(([name, dataItem]) => {
2389
+ const value = dataItem.value;
2390
+ return [name, value];
2391
+ }));
2392
+ }
2393
+ /** @internal */
2394
+ function submit() {
2395
+ const systemConfig = getSystem();
2396
+ const campaignId = systemConfig.campaignId;
2397
+ if (campaignId) {
2398
+ const formData$1 = get(formData);
2399
+ const identifyFormData$1 = get(identifyFormData);
2400
+ const values = formDataToEventValues(campaignId, formData$1);
2401
+ const identifyValues = formDataToIdentifyEventValues(identifyFormData$1);
2402
+ if (Object.keys(identifyValues).length > 0) {
2403
+ identifyValues['user_id'] = getVariables()?.[USER_ID_VARIABLE_NAME];
2404
+ }
2405
+ return { values, identifyValues };
2406
+ }
2407
+ return {};
2408
+ }
2409
+ /**
2410
+ * 選択式のアンケート回答を追加する
2411
+ *
2412
+ * @param questionId - 質問ID
2413
+ * @param choices - 回答内容
2414
+ *
2415
+ * @public
2416
+ */
2417
+ function addChoiceAnswer(questionId, choices, validation) {
2418
+ formData.update(prev => ({
2419
+ ...prev,
2420
+ [questionId]: {
2421
+ value: choices,
2422
+ statePath: validation?.statePath ?? '',
2423
+ isValid: validation?.isValid ?? true,
2424
+ },
2425
+ }));
2426
+ }
2427
+ /**
2428
+ * 自由記述式のアンケート回答を追加する
2429
+ *
2430
+ * @param questionId - 質問ID
2431
+ * @param freeAnswer - 回答内容
2432
+ *
2433
+ * @public
2434
+ */
2435
+ function addFreeAnswer(questionId, freeAnswer, validation) {
2436
+ formData.update(prev => ({
2437
+ ...prev,
2438
+ [questionId]: {
2439
+ value: freeAnswer.slice(0, MAX_LENGTH_FREE_ANSWER),
2440
+ statePath: validation?.statePath ?? '',
2441
+ isValid: validation?.isValid ?? true,
2442
+ },
2443
+ }));
2444
+ }
2445
+ /**
2446
+ * 回答済の回答を削除
2447
+ *
2448
+ * @param questionId - 質問ID
2449
+ *
2450
+ * @public
2451
+ */
2452
+ function removeAnswer(questionId) {
2453
+ formData.update(prev => {
2454
+ const next = { ...prev };
2455
+ delete next[questionId];
2456
+ return next;
2457
+ });
2458
+ }
2459
+ /**
2460
+ * 回答済の回答内容を取得する
2461
+ *
2462
+ * @param questionId - 質問ID
2463
+ *
2464
+ * @returns 回答データ
2465
+ *
2466
+ * @public
2467
+ */
2468
+ function getAnsweredQuestion(questionId) {
2469
+ const formData$1 = get(formData);
2470
+ const valueState = formData$1[questionId];
2471
+ if (valueState) {
2472
+ return createAnswerValue(valueState.value);
2473
+ }
2474
+ }
2475
+ /**
2476
+ * 回答済の回答IDのリストを取得
2477
+ *
2478
+ * @returns 回答済の質問の質問IDの配列
2479
+ *
2480
+ * @public
2481
+ */
2482
+ function getAnsweredQuestionIds() {
2483
+ const formData$1 = get(formData);
2484
+ return Object.keys(formData$1);
2485
+ }
2486
+ /**
2487
+ * `sendAnswers`のエイリアス
2488
+ *
2489
+ * @public
2490
+ */
2491
+ function sendAnswer() {
2492
+ return sendAnswers();
2493
+ }
2494
+ // NOTE: sendAnswers用
2495
+ let isSent = false;
2496
+ /**
2497
+ * 回答済の回答をまとめてイベントとして送信する
2498
+ *
2499
+ * @returns イベント送信の成功/失敗
2500
+ *
2501
+ * @public
2502
+ */
2503
+ function sendAnswers() {
2504
+ const { values, identifyValues } = submit();
2505
+ if (isSent)
2506
+ return false;
2507
+ if (Object.keys(values ?? {}).length === 0 && Object.keys(identifyValues ?? {}).length === 0) {
2508
+ return false;
2509
+ }
2510
+ send_event('_answer_question', values);
2511
+ if (Object.keys(identifyValues ?? {}).length > 0) {
2512
+ send_event('identify', identifyValues);
2513
+ }
2514
+ isSent = true;
2515
+ return true;
2516
+ }
2517
+
2258
2518
  /**
2259
2519
  * エディタv1のWidget API 互換のインターフェース
2260
2520
  */
@@ -2913,134 +3173,6 @@ class StateItem extends SvelteComponent {
2913
3173
  }
2914
3174
  }
2915
3175
 
2916
- const USER_ID_VARIABLE_NAME = '__karte_form_identify_user_id';
2917
- function isEmpty(value) {
2918
- if (Array.isArray(value)) {
2919
- return value.length === 0;
2920
- }
2921
- else {
2922
- return !value;
2923
- }
2924
- }
2925
- /** @internal */
2926
- function createInputRegisterer(formData) {
2927
- const registerInput = ({ name, statePath, validator = () => true, initialValue, }) => {
2928
- const writableValue = {
2929
- subscribe(run) {
2930
- return formData.subscribe(formData => {
2931
- run(formData[name]?.value);
2932
- });
2933
- },
2934
- set(value) {
2935
- formData.update(prev => ({
2936
- ...prev,
2937
- [name]: {
2938
- statePath,
2939
- value,
2940
- isValid: validator(value),
2941
- },
2942
- }));
2943
- },
2944
- update(updater) {
2945
- formData.update(prev => {
2946
- const prevValue = prev[name]?.value;
2947
- if (prevValue === undefined)
2948
- return prev;
2949
- const value = updater(prevValue);
2950
- return {
2951
- ...prev,
2952
- [name]: {
2953
- statePath,
2954
- value,
2955
- isValid: validator(value),
2956
- },
2957
- };
2958
- });
2959
- },
2960
- };
2961
- const readableIsValid = {
2962
- subscribe(run) {
2963
- return formData.subscribe(formData => {
2964
- run(formData[name]?.isValid);
2965
- });
2966
- },
2967
- };
2968
- if (isEmpty(get(writableValue))) {
2969
- writableValue.set(initialValue);
2970
- }
2971
- return {
2972
- value: writableValue,
2973
- isValid: readableIsValid,
2974
- };
2975
- };
2976
- return registerInput;
2977
- }
2978
- /** @internal */
2979
- const registerInput = createInputRegisterer(formData);
2980
- /** @internal */
2981
- const registerIdentifyInput = createInputRegisterer(identifyFormData);
2982
- function validateFormData(formData, statePath) {
2983
- return Object.entries(formData)
2984
- .filter(([_, { statePath: s }]) => s === statePath) // eslint-disable-line @typescript-eslint/no-unused-vars
2985
- .every(([_, { isValid }]) => isValid); // eslint-disable-line @typescript-eslint/no-unused-vars
2986
- }
2987
- /** @internal */
2988
- const getValuesAreValidReadable = statePath => ({
2989
- subscribe(callback) {
2990
- return formData.subscribe(formData => identifyFormData.subscribe(identifyFormData => {
2991
- const valuesAreValid = validateFormData(formData, statePath) && validateFormData(identifyFormData, statePath);
2992
- callback(valuesAreValid);
2993
- }));
2994
- },
2995
- });
2996
- function formDataToEventValues(campaignId, formData) {
2997
- const questions = [];
2998
- const answersMap = {};
2999
- Object.entries(formData).forEach(([name, dataItem]) => {
3000
- questions.push(name);
3001
- const value = dataItem.value;
3002
- const answerKey = `question_${name}`;
3003
- if (Array.isArray(value)) {
3004
- answersMap[answerKey] = {
3005
- choices: value,
3006
- };
3007
- }
3008
- else if (typeof value === 'string') {
3009
- answersMap[answerKey] = {
3010
- free_answer: value,
3011
- };
3012
- }
3013
- });
3014
- return {
3015
- [campaignId]: {
3016
- questions,
3017
- ...answersMap,
3018
- },
3019
- };
3020
- }
3021
- function formDataToIdentifyEventValues(formData) {
3022
- return Object.fromEntries(Object.entries(formData).map(([name, dataItem]) => {
3023
- const value = dataItem.value;
3024
- return [name, value];
3025
- }));
3026
- }
3027
- /** @internal */
3028
- function submit() {
3029
- const systemConfig = getSystem();
3030
- const campaignId = systemConfig.campaignId;
3031
- if (campaignId) {
3032
- const formData$1 = get(formData);
3033
- const identifyFormData$1 = get(identifyFormData);
3034
- const values = formDataToEventValues(campaignId, formData$1);
3035
- const identifyValues = formDataToIdentifyEventValues(identifyFormData$1);
3036
- if (Object.keys(identifyValues).length > 0) {
3037
- identifyValues['user_id'] = getVariables()?.[USER_ID_VARIABLE_NAME];
3038
- }
3039
- return { values, identifyValues };
3040
- }
3041
- return {};
3042
- }
3043
-
3044
3176
  /**
3045
3177
  * モーダル(ポップアップ)のコンポーネントが利用するコードの管理
3046
3178
  */
@@ -11751,4 +11883,4 @@ class ImageBlock extends SvelteComponent {
11751
11883
  }
11752
11884
  }
11753
11885
 
11754
- export { ACTION_HOOK_LABEL, Alignments, AnimationStyles, BackgroundSizes, Box, ClipPaths, CodeElement, Countdown, Cursors, DefaultEdgePosition, DefaultElasticity, DefaultFormButtonColor, DefaultFormIdentifyBooleanField, DefaultFormIdentifyTextField, DefaultListBackground, DefaultListBackgroundNone, DefaultListBackgroundStripe, DefaultListSeparator, DefaultListSeparatorBorder, DefaultListSeparatorGap, DefaultListSeparatorNone, DefaultModalBreakPoint, DefaultModalPlacement, DefaultSlideButton, DefaultSlideNavigationButton, Directions, Elasticities, ElasticityStyle, EmbedElement, Flex, FlexDirections, FlexItem, Fonts, FormCheckBoxes, FormIdentifyBooleanFields, FormIdentifyChoices, FormIdentifyInput, FormIdentifyTextFieldPlaceholders, FormIdentifyTextFieldValidations, FormIdentifyTextFields, FormRadioButtons, FormRatingButtonsFace, FormRatingButtonsNumber, FormSelect, FormTextarea, Grid, GridItem, GridModalState, IconElement, ImageBlock, ImageElement, Justifies, KARTE_MODAL_ROOT, LAYOUT_COMPONENT_NAMES, LengthUnits, List, ListBackgroundTypes, ListDirections, ListItem, ListSeparatorTypes, MediaQueries, Modal, ModalPositions, MovieVimeoElement, MovieYouTubeElement, ObjectFits, OnClickOperationOptions, Overflows, PropTypes, Repeats, SYSTEM_FONT, Slide, SlideItem, State, StateItem, TextBlock, TextButtonBlock, TextButtonElement, TextDirections, TextElement, WritingModes, afterUpdate, applyCss, applyGlobalCss, beforeUpdate, close, closeAction, collection$1 as collection, create, createApp, createFog, destroy, destroyAction, ensureModalRoot, eventHandlers, finalize, formData, getActionRoot, getCssVariables, getEventHandlers, getEvents, getLogs, getState$1 as getState, getStates, getSystem, getVariables, hideOnScroll, hideOnTime, initialize, isOpened, listenLogger, loadActionTable, loadActionTableQuery, loadActionTableRow, loadActionTableRows, loadGlobalScript, loadGlobalStyle, loadStyle, logger, onChangeState, onClose, onCreate, onDestory, onDestroy, onMount, onScroll, onShow, onTime, resetEventHandlers, resetVariables, setEventHandlers, setSetting, setState$1 as setState, setVariables, show, showAction, showModal, showOnScroll, showOnTime, state, tick, variables, widget };
11886
+ export { ACTION_HOOK_LABEL, Alignments, AnimationStyles, BackgroundSizes, Box, ClipPaths, CodeElement, Countdown, Cursors, DefaultEdgePosition, DefaultElasticity, DefaultFormButtonColor, DefaultFormIdentifyBooleanField, DefaultFormIdentifyTextField, DefaultListBackground, DefaultListBackgroundNone, DefaultListBackgroundStripe, DefaultListSeparator, DefaultListSeparatorBorder, DefaultListSeparatorGap, DefaultListSeparatorNone, DefaultModalBreakPoint, DefaultModalPlacement, DefaultSlideButton, DefaultSlideNavigationButton, Directions, Elasticities, ElasticityStyle, EmbedElement, Flex, FlexDirections, FlexItem, Fonts, FormCheckBoxes, FormIdentifyBooleanFields, FormIdentifyChoices, FormIdentifyInput, FormIdentifyTextFieldPlaceholders, FormIdentifyTextFieldValidations, FormIdentifyTextFields, FormRadioButtons, FormRatingButtonsFace, FormRatingButtonsNumber, FormSelect, FormTextarea, Grid, GridItem, GridModalState, IconElement, ImageBlock, ImageElement, Justifies, KARTE_MODAL_ROOT, LAYOUT_COMPONENT_NAMES, LengthUnits, List, ListBackgroundTypes, ListDirections, ListItem, ListSeparatorTypes, MediaQueries, Modal, ModalPositions, MovieVimeoElement, MovieYouTubeElement, ObjectFits, OnClickOperationOptions, Overflows, PropTypes, Repeats, SYSTEM_FONT, Slide, SlideItem, State, StateItem, TextBlock, TextButtonBlock, TextButtonElement, TextDirections, TextElement, WritingModes, addChoiceAnswer, addFreeAnswer, afterUpdate, applyCss, applyGlobalCss, beforeUpdate, close, closeAction, collection$1 as collection, create, createApp, createFog, destroy, destroyAction, ensureModalRoot, eventHandlers, finalize, formData, getActionRoot, getAnsweredQuestion, getAnsweredQuestionIds, getCssVariables, getEventHandlers, getEvents, getLogs, getState$1 as getState, getStates, getSystem, getVariables, hideOnScroll, hideOnTime, initialize, isOpened, listenLogger, loadActionTable, loadActionTableQuery, loadActionTableRow, loadActionTableRows, loadGlobalScript, loadGlobalStyle, loadStyle, logger, onChangeState, onClose, onCreate, onDestory, onDestroy, onMount, onScroll, onShow, onTime, removeAnswer, resetEventHandlers, resetVariables, sendAnswer, sendAnswers, setEventHandlers, setSetting, setState$1 as setState, setVariables, show, showAction, showModal, showOnScroll, showOnTime, state, tick, variables, widget };
@@ -192,25 +192,19 @@ type ActionTableQueryParams = {
192
192
  /**
193
193
  * アクションテーブルの設定情報
194
194
  *
195
- * @public
195
+ * @param api_key - API Key
196
+ * @param table - テーブル名
197
+ * @param endpoint - エンドポイント / 指定がない場合はデフォルトのエンドポイントを使用します。検証用途以外での通常利用では指定なしで大丈夫です。
196
198
  */
197
199
  type CollectionConfig = {
198
- /**
199
- * APIキー
200
- */
201
200
  api_key: string;
202
- /**
203
- * テーブル名
204
- */
205
201
  table: string;
206
- /**
207
- * エンドポイント
208
- */ endpoint?: string;
202
+ endpoint?: string;
209
203
  };
210
204
  /**
211
205
  * アクションテーブルを管理するメソッドを取得する
212
206
  *
213
- * @param config - 設定情報
207
+ * @param config - アクションテーブル設定情報
214
208
  *
215
209
  * @returns メソッドを返します
216
210
  *
@@ -1515,6 +1509,75 @@ declare function createFog({ color, opacity, zIndex, onclick }: {
1515
1509
  fog: HTMLDivElement;
1516
1510
  close: () => void;
1517
1511
  };
1512
+ type AnswerValue = {
1513
+ choices: string[];
1514
+ } | {
1515
+ free_answer: string;
1516
+ };
1517
+ /**
1518
+ * 選択式のアンケート回答を追加する
1519
+ *
1520
+ * @param questionId - 質問ID
1521
+ * @param choices - 回答内容
1522
+ *
1523
+ * @public
1524
+ */
1525
+ declare function addChoiceAnswer(questionId: string, choices: string[], validation?: {
1526
+ isValid: boolean;
1527
+ statePath: string;
1528
+ }): void;
1529
+ /**
1530
+ * 自由記述式のアンケート回答を追加する
1531
+ *
1532
+ * @param questionId - 質問ID
1533
+ * @param freeAnswer - 回答内容
1534
+ *
1535
+ * @public
1536
+ */
1537
+ declare function addFreeAnswer(questionId: string, freeAnswer: string, validation?: {
1538
+ isValid: boolean;
1539
+ statePath: string;
1540
+ }): void;
1541
+ /**
1542
+ * 回答済の回答を削除
1543
+ *
1544
+ * @param questionId - 質問ID
1545
+ *
1546
+ * @public
1547
+ */
1548
+ declare function removeAnswer(questionId: string): void;
1549
+ /**
1550
+ * 回答済の回答内容を取得する
1551
+ *
1552
+ * @param questionId - 質問ID
1553
+ *
1554
+ * @returns 回答データ
1555
+ *
1556
+ * @public
1557
+ */
1558
+ declare function getAnsweredQuestion(questionId: string): AnswerValue | undefined;
1559
+ /**
1560
+ * 回答済の回答IDのリストを取得
1561
+ *
1562
+ * @returns 回答済の質問の質問IDの配列
1563
+ *
1564
+ * @public
1565
+ */
1566
+ declare function getAnsweredQuestionIds(): string[];
1567
+ /**
1568
+ * `sendAnswers`のエイリアス
1569
+ *
1570
+ * @public
1571
+ */
1572
+ declare function sendAnswer(): boolean;
1573
+ /**
1574
+ * 回答済の回答をまとめてイベントとして送信する
1575
+ *
1576
+ * @returns イベント送信の成功/失敗
1577
+ *
1578
+ * @public
1579
+ */
1580
+ declare function sendAnswers(): boolean;
1518
1581
  declare namespace widget {
1519
1582
  /**
1520
1583
  * アクションの汎用的なタイプを定義する
@@ -1692,25 +1755,19 @@ declare namespace widget {
1692
1755
  /**
1693
1756
  * アクションテーブルの設定情報
1694
1757
  *
1695
- * @public
1758
+ * @param api_key - API Key
1759
+ * @param table - テーブル名
1760
+ * @param endpoint - エンドポイント / 指定がない場合はデフォルトのエンドポイントを使用します。検証用途以外での通常利用では指定なしで大丈夫です。
1696
1761
  */
1697
1762
  type CollectionConfig = {
1698
- /**
1699
- * APIキー
1700
- */
1701
1763
  api_key: string;
1702
- /**
1703
- * テーブル名
1704
- */
1705
1764
  table: string;
1706
- /**
1707
- * エンドポイント
1708
- */ endpoint?: string;
1765
+ endpoint?: string;
1709
1766
  };
1710
1767
  /**
1711
1768
  * アクションテーブルを管理するメソッドを取得する
1712
1769
  *
1713
- * @param config - 設定情報
1770
+ * @param config - アクションテーブル設定情報
1714
1771
  *
1715
1772
  * @returns メソッドを返します
1716
1773
  *
@@ -2277,7 +2334,7 @@ declare const afterUpdate: typeof afterUpdateSvelte;
2277
2334
  declare const tick: typeof tickSvelte;
2278
2335
  // @internal
2279
2336
  declare const LAYOUT_COMPONENT_NAMES: string[];
2280
- export { ACTION_HOOK_LABEL, KARTE_MODAL_ROOT, create, destroyAction, onCreate, onDestroy, showModal, destroy, initialize, finalize, loadGlobalScript, loadGlobalStyle, applyGlobalCss, getState, setState, getStates, isOpened, getVariables, setVariables, resetVariables, getEventHandlers, setEventHandlers, resetEventHandlers, getSystem, setSetting, eventHandlers, variables, formData, state, onScroll, onTime, getLogs, getEvents, logger, listenLogger, hideOnScroll, hideOnTime, showOnScroll, showOnTime, PropTypes, PropType, Code, MediaQueries, MediaQuery, Directions, Direction, AnimationStyles, AnimationStyle, ModalPositions, ModalPosition, ModalMargin, ModalPlacement, DefaultModalPlacement, Elasticities, Elasticity, ElasticityStyle, DefaultElasticity, TextDirections, TextDirection, OperationArgumentType, Operation, OnClickOperationOptions, OnClickOperation, LongText, Url, RegExpProp, Image, LengthUnits, LengthUnit, Length, Color, FontWeight, SYSTEM_FONT, Fonts, Font, Justifies, Justify, Alignments, Alignment, FlexDirections, FlexDirection, ObjectFits, ObjectFit, ClipPaths, ClipPath, Repeats, Repeat, BackgroundSizes, BackgroundSize, Cursors, Cursor, Overflows, Overflow, Border, BorderStyle, BorderWidth, BoxShadow, Style, TransitState, WritingModes, WritingMode, DateTime, Icon, ListSeparatorTypes, EdgePosition, DefaultEdgePosition, ListSeparatorNone, ListSeparatorBorder, ListSeparatorGap, ListSeparator, DefaultListSeparatorNone, DefaultListSeparatorBorder, DefaultListSeparatorGap, DefaultListSeparator, ListBackgroundTypes, ListBackgroundNone, ListBackgroundStripe, ListBackground, DefaultListBackgroundNone, DefaultListBackgroundStripe, DefaultListBackground, ListDirections, ListDirection, ListContext, SlideButtonIcon, SlideButtonText, SlideButton, DefaultSlideButton, SlideButtonPosition, SlideNavigationButton, DefaultSlideNavigationButton, FormInputName, FormButtonColor, DefaultFormButtonColor, ModalStyle, ModalBreakPoint, DefaultModalBreakPoint, FormIdentifyTextFields, FormIdentifyTextField, FormIdentifyTextFieldValidations, FormIdentifyTextFieldPlaceholders, DefaultFormIdentifyTextField, FormIdentifyBooleanFields, FormIdentifyBooleanField, DefaultFormIdentifyBooleanField, showAction, closeAction, loadStyle, applyCss, onShow, onClose, onChangeState, getActionRoot, getCssVariables, show, close, ensureModalRoot, createApp, createFog, collection, loadActionTableRow, loadActionTableRows, loadActionTableQuery, loadActionTable, widget, onMount, onDestory, beforeUpdate, afterUpdate, tick, LAYOUT_COMPONENT_NAMES };
2337
+ export { ACTION_HOOK_LABEL, KARTE_MODAL_ROOT, create, destroyAction, onCreate, onDestroy, showModal, destroy, initialize, finalize, loadGlobalScript, loadGlobalStyle, applyGlobalCss, getState, setState, getStates, isOpened, getVariables, setVariables, resetVariables, getEventHandlers, setEventHandlers, resetEventHandlers, getSystem, setSetting, eventHandlers, variables, formData, state, onScroll, onTime, getLogs, getEvents, logger, listenLogger, hideOnScroll, hideOnTime, showOnScroll, showOnTime, PropTypes, PropType, Code, MediaQueries, MediaQuery, Directions, Direction, AnimationStyles, AnimationStyle, ModalPositions, ModalPosition, ModalMargin, ModalPlacement, DefaultModalPlacement, Elasticities, Elasticity, ElasticityStyle, DefaultElasticity, TextDirections, TextDirection, OperationArgumentType, Operation, OnClickOperationOptions, OnClickOperation, LongText, Url, RegExpProp, Image, LengthUnits, LengthUnit, Length, Color, FontWeight, SYSTEM_FONT, Fonts, Font, Justifies, Justify, Alignments, Alignment, FlexDirections, FlexDirection, ObjectFits, ObjectFit, ClipPaths, ClipPath, Repeats, Repeat, BackgroundSizes, BackgroundSize, Cursors, Cursor, Overflows, Overflow, Border, BorderStyle, BorderWidth, BoxShadow, Style, TransitState, WritingModes, WritingMode, DateTime, Icon, ListSeparatorTypes, EdgePosition, DefaultEdgePosition, ListSeparatorNone, ListSeparatorBorder, ListSeparatorGap, ListSeparator, DefaultListSeparatorNone, DefaultListSeparatorBorder, DefaultListSeparatorGap, DefaultListSeparator, ListBackgroundTypes, ListBackgroundNone, ListBackgroundStripe, ListBackground, DefaultListBackgroundNone, DefaultListBackgroundStripe, DefaultListBackground, ListDirections, ListDirection, ListContext, SlideButtonIcon, SlideButtonText, SlideButton, DefaultSlideButton, SlideButtonPosition, SlideNavigationButton, DefaultSlideNavigationButton, FormInputName, FormButtonColor, DefaultFormButtonColor, ModalStyle, ModalBreakPoint, DefaultModalBreakPoint, FormIdentifyTextFields, FormIdentifyTextField, FormIdentifyTextFieldValidations, FormIdentifyTextFieldPlaceholders, DefaultFormIdentifyTextField, FormIdentifyBooleanFields, FormIdentifyBooleanField, DefaultFormIdentifyBooleanField, showAction, closeAction, loadStyle, applyCss, onShow, onClose, onChangeState, getActionRoot, getCssVariables, show, close, ensureModalRoot, createApp, createFog, collection, loadActionTableRow, loadActionTableRows, loadActionTableQuery, loadActionTable, addChoiceAnswer, addFreeAnswer, removeAnswer, getAnsweredQuestion, getAnsweredQuestionIds, sendAnswer, sendAnswers, widget, onMount, onDestory, beforeUpdate, afterUpdate, tick, LAYOUT_COMPONENT_NAMES };
2281
2338
  export type { SystemConfig, ActionVariables, ActionEventHandler, ActionProps, ActionOptions, ActionHook, ActionHookLog, ActionChangeStateHook, SendFunction, PublishFunction, OnScrollContext, OnScrollFunction, ScrollDirection, LogLevel, Log, Event, ActionCloseHook, ShowTrigger, CloseTrigger, CollectionConfig, ActionTableRowRequestConfig, ActionTableRowsRequestConfig, ActionTableQueryRequestConfig, ActionTableRequestConfig };
2282
2339
  export { default as State } from './components/State.svelte';
2283
2340
  export { default as StateItem } from './components/StateItem.svelte';
package/dist/index.es.js CHANGED
@@ -1361,7 +1361,7 @@ const DEFAULT_COLLECTION_ENDPOINT = typeof __FLYER_GEN_COLLECTION_API_ENDPOINT__
1361
1361
  /**
1362
1362
  * アクションテーブルを管理するメソッドを取得する
1363
1363
  *
1364
- * @param config - 設定情報
1364
+ * @param config - アクションテーブル設定情報
1365
1365
  *
1366
1366
  * @returns メソッドを返します
1367
1367
  *
@@ -1372,6 +1372,14 @@ function collection$1(config) {
1372
1372
  const api_key = config.api_key;
1373
1373
  const table = config.table;
1374
1374
  return {
1375
+ /**
1376
+ * キーを1つ、または複数指定して、対応するアクションテーブルの行を取得する
1377
+ *
1378
+ * @param key - 取得する行のキーを一つ、または複数配列で指定
1379
+ * @param cb - テーブルの行を取得した後に実行するcallback関数
1380
+ *
1381
+ * @public
1382
+ */
1375
1383
  get(key, cb) {
1376
1384
  if (Array.isArray(key)) {
1377
1385
  return request(`${endpoint}/getByKeys`, {
@@ -1381,15 +1389,25 @@ function collection$1(config) {
1381
1389
  }, cb);
1382
1390
  }
1383
1391
  else {
1384
- request(`${endpoint}/getByKey`, {
1392
+ return request(`${endpoint}/getByKey`, {
1385
1393
  api_key,
1386
1394
  name: table,
1387
1395
  key,
1388
1396
  }, cb);
1389
1397
  }
1390
1398
  },
1399
+ /**
1400
+ * クエリーを指定して、アクションテーブルから行を取得する
1401
+ * なお、クエリーは事前に管理画面で設定しておく必要があります。
1402
+ *
1403
+ * @param query_name - クエリー名
1404
+ * @param params - クエリーに指定するパラメーター。 `{key: value}` の形式で指定
1405
+ * @param cb - テーブルの行を取得した後に実行するcallback関数
1406
+ *
1407
+ * @public
1408
+ */
1391
1409
  getByQuery(query_name, params, options, cb) {
1392
- request(`${endpoint}/getByQuery`, {
1410
+ return request(`${endpoint}/getByQuery`, {
1393
1411
  api_key,
1394
1412
  name: table,
1395
1413
  query_name,
@@ -1397,6 +1415,7 @@ function collection$1(config) {
1397
1415
  options,
1398
1416
  }, cb);
1399
1417
  },
1418
+ /** @internal */
1400
1419
  set(key, value, cb) {
1401
1420
  request(`${endpoint}/set`, {
1402
1421
  api_key,
@@ -2312,6 +2331,247 @@ function destroy() {
2312
2331
  dispatchDestroyEvent();
2313
2332
  }
2314
2333
 
2334
+ const USER_ID_VARIABLE_NAME = '__karte_form_identify_user_id';
2335
+ const MAX_LENGTH_FREE_ANSWER = 2000;
2336
+ function isEmpty(value) {
2337
+ if (Array.isArray(value)) {
2338
+ return value.length === 0;
2339
+ }
2340
+ else {
2341
+ return !value;
2342
+ }
2343
+ }
2344
+ /** @internal */
2345
+ function createInputRegisterer(formData) {
2346
+ const registerInput = ({ name, statePath, validator = () => true, initialValue, }) => {
2347
+ const writableValue = {
2348
+ subscribe(run) {
2349
+ return formData.subscribe(formData => {
2350
+ run(formData[name]?.value);
2351
+ });
2352
+ },
2353
+ set(value) {
2354
+ formData.update(prev => ({
2355
+ ...prev,
2356
+ [name]: {
2357
+ statePath,
2358
+ value,
2359
+ isValid: validator(value),
2360
+ },
2361
+ }));
2362
+ },
2363
+ update(updater) {
2364
+ formData.update(prev => {
2365
+ const prevValue = prev[name]?.value;
2366
+ if (prevValue === undefined)
2367
+ return prev;
2368
+ const value = updater(prevValue);
2369
+ return {
2370
+ ...prev,
2371
+ [name]: {
2372
+ statePath,
2373
+ value,
2374
+ isValid: validator(value),
2375
+ },
2376
+ };
2377
+ });
2378
+ },
2379
+ };
2380
+ const readableIsValid = {
2381
+ subscribe(run) {
2382
+ return formData.subscribe(formData => {
2383
+ run(formData[name]?.isValid);
2384
+ });
2385
+ },
2386
+ };
2387
+ if (isEmpty(get(writableValue))) {
2388
+ writableValue.set(initialValue);
2389
+ }
2390
+ return {
2391
+ value: writableValue,
2392
+ isValid: readableIsValid,
2393
+ };
2394
+ };
2395
+ return registerInput;
2396
+ }
2397
+ /** @internal */
2398
+ const registerInput = createInputRegisterer(formData);
2399
+ /** @internal */
2400
+ const registerIdentifyInput = createInputRegisterer(identifyFormData);
2401
+ function validateFormData(formData, statePath) {
2402
+ return Object.entries(formData)
2403
+ .filter(([_, { statePath: s }]) => s === statePath) // eslint-disable-line @typescript-eslint/no-unused-vars
2404
+ .every(([_, { isValid }]) => isValid); // eslint-disable-line @typescript-eslint/no-unused-vars
2405
+ }
2406
+ /** @internal */
2407
+ const getValuesAreValidReadable = statePath => ({
2408
+ subscribe(callback) {
2409
+ return formData.subscribe(formData => identifyFormData.subscribe(identifyFormData => {
2410
+ const valuesAreValid = validateFormData(formData, statePath) && validateFormData(identifyFormData, statePath);
2411
+ callback(valuesAreValid);
2412
+ }));
2413
+ },
2414
+ });
2415
+ function createAnswerValue(value) {
2416
+ if (Array.isArray(value)) {
2417
+ return {
2418
+ choices: value,
2419
+ };
2420
+ }
2421
+ else if (typeof value === 'string') {
2422
+ return {
2423
+ free_answer: value,
2424
+ };
2425
+ }
2426
+ }
2427
+ function formDataToEventValues(campaignId, formData) {
2428
+ const questions = [];
2429
+ const answersMap = {};
2430
+ Object.entries(formData).forEach(([name, dataItem]) => {
2431
+ questions.push(name);
2432
+ const value = dataItem.value;
2433
+ const answerKey = `question_${name}`;
2434
+ const answerValue = createAnswerValue(value);
2435
+ answersMap[answerKey] = answerValue;
2436
+ });
2437
+ return {
2438
+ [campaignId]: {
2439
+ questions,
2440
+ ...answersMap,
2441
+ },
2442
+ };
2443
+ }
2444
+ function formDataToIdentifyEventValues(formData) {
2445
+ return Object.fromEntries(Object.entries(formData).map(([name, dataItem]) => {
2446
+ const value = dataItem.value;
2447
+ return [name, value];
2448
+ }));
2449
+ }
2450
+ /** @internal */
2451
+ function submit() {
2452
+ const systemConfig = getSystem();
2453
+ const campaignId = systemConfig.campaignId;
2454
+ if (campaignId) {
2455
+ const formData$1 = get(formData);
2456
+ const identifyFormData$1 = get(identifyFormData);
2457
+ const values = formDataToEventValues(campaignId, formData$1);
2458
+ const identifyValues = formDataToIdentifyEventValues(identifyFormData$1);
2459
+ if (Object.keys(identifyValues).length > 0) {
2460
+ identifyValues['user_id'] = getVariables()?.[USER_ID_VARIABLE_NAME];
2461
+ }
2462
+ return { values, identifyValues };
2463
+ }
2464
+ return {};
2465
+ }
2466
+ /**
2467
+ * 選択式のアンケート回答を追加する
2468
+ *
2469
+ * @param questionId - 質問ID
2470
+ * @param choices - 回答内容
2471
+ *
2472
+ * @public
2473
+ */
2474
+ function addChoiceAnswer(questionId, choices, validation) {
2475
+ formData.update(prev => ({
2476
+ ...prev,
2477
+ [questionId]: {
2478
+ value: choices,
2479
+ statePath: validation?.statePath ?? '',
2480
+ isValid: validation?.isValid ?? true,
2481
+ },
2482
+ }));
2483
+ }
2484
+ /**
2485
+ * 自由記述式のアンケート回答を追加する
2486
+ *
2487
+ * @param questionId - 質問ID
2488
+ * @param freeAnswer - 回答内容
2489
+ *
2490
+ * @public
2491
+ */
2492
+ function addFreeAnswer(questionId, freeAnswer, validation) {
2493
+ formData.update(prev => ({
2494
+ ...prev,
2495
+ [questionId]: {
2496
+ value: freeAnswer.slice(0, MAX_LENGTH_FREE_ANSWER),
2497
+ statePath: validation?.statePath ?? '',
2498
+ isValid: validation?.isValid ?? true,
2499
+ },
2500
+ }));
2501
+ }
2502
+ /**
2503
+ * 回答済の回答を削除
2504
+ *
2505
+ * @param questionId - 質問ID
2506
+ *
2507
+ * @public
2508
+ */
2509
+ function removeAnswer(questionId) {
2510
+ formData.update(prev => {
2511
+ const next = { ...prev };
2512
+ delete next[questionId];
2513
+ return next;
2514
+ });
2515
+ }
2516
+ /**
2517
+ * 回答済の回答内容を取得する
2518
+ *
2519
+ * @param questionId - 質問ID
2520
+ *
2521
+ * @returns 回答データ
2522
+ *
2523
+ * @public
2524
+ */
2525
+ function getAnsweredQuestion(questionId) {
2526
+ const formData$1 = get(formData);
2527
+ const valueState = formData$1[questionId];
2528
+ if (valueState) {
2529
+ return createAnswerValue(valueState.value);
2530
+ }
2531
+ }
2532
+ /**
2533
+ * 回答済の回答IDのリストを取得
2534
+ *
2535
+ * @returns 回答済の質問の質問IDの配列
2536
+ *
2537
+ * @public
2538
+ */
2539
+ function getAnsweredQuestionIds() {
2540
+ const formData$1 = get(formData);
2541
+ return Object.keys(formData$1);
2542
+ }
2543
+ /**
2544
+ * `sendAnswers`のエイリアス
2545
+ *
2546
+ * @public
2547
+ */
2548
+ function sendAnswer() {
2549
+ return sendAnswers();
2550
+ }
2551
+ // NOTE: sendAnswers用
2552
+ let isSent = false;
2553
+ /**
2554
+ * 回答済の回答をまとめてイベントとして送信する
2555
+ *
2556
+ * @returns イベント送信の成功/失敗
2557
+ *
2558
+ * @public
2559
+ */
2560
+ function sendAnswers() {
2561
+ const { values, identifyValues } = submit();
2562
+ if (isSent)
2563
+ return false;
2564
+ if (Object.keys(values ?? {}).length === 0 && Object.keys(identifyValues ?? {}).length === 0) {
2565
+ return false;
2566
+ }
2567
+ send_event('_answer_question', values);
2568
+ if (Object.keys(identifyValues ?? {}).length > 0) {
2569
+ send_event('identify', identifyValues);
2570
+ }
2571
+ isSent = true;
2572
+ return true;
2573
+ }
2574
+
2315
2575
  /**
2316
2576
  * エディタv1のWidget API 互換のインターフェース
2317
2577
  */
@@ -2937,134 +3197,6 @@ class StateItem extends SvelteComponent {
2937
3197
  }
2938
3198
  }
2939
3199
 
2940
- const USER_ID_VARIABLE_NAME = '__karte_form_identify_user_id';
2941
- function isEmpty(value) {
2942
- if (Array.isArray(value)) {
2943
- return value.length === 0;
2944
- }
2945
- else {
2946
- return !value;
2947
- }
2948
- }
2949
- /** @internal */
2950
- function createInputRegisterer(formData) {
2951
- const registerInput = ({ name, statePath, validator = () => true, initialValue, }) => {
2952
- const writableValue = {
2953
- subscribe(run) {
2954
- return formData.subscribe(formData => {
2955
- run(formData[name]?.value);
2956
- });
2957
- },
2958
- set(value) {
2959
- formData.update(prev => ({
2960
- ...prev,
2961
- [name]: {
2962
- statePath,
2963
- value,
2964
- isValid: validator(value),
2965
- },
2966
- }));
2967
- },
2968
- update(updater) {
2969
- formData.update(prev => {
2970
- const prevValue = prev[name]?.value;
2971
- if (prevValue === undefined)
2972
- return prev;
2973
- const value = updater(prevValue);
2974
- return {
2975
- ...prev,
2976
- [name]: {
2977
- statePath,
2978
- value,
2979
- isValid: validator(value),
2980
- },
2981
- };
2982
- });
2983
- },
2984
- };
2985
- const readableIsValid = {
2986
- subscribe(run) {
2987
- return formData.subscribe(formData => {
2988
- run(formData[name]?.isValid);
2989
- });
2990
- },
2991
- };
2992
- if (isEmpty(get(writableValue))) {
2993
- writableValue.set(initialValue);
2994
- }
2995
- return {
2996
- value: writableValue,
2997
- isValid: readableIsValid,
2998
- };
2999
- };
3000
- return registerInput;
3001
- }
3002
- /** @internal */
3003
- const registerInput = createInputRegisterer(formData);
3004
- /** @internal */
3005
- const registerIdentifyInput = createInputRegisterer(identifyFormData);
3006
- function validateFormData(formData, statePath) {
3007
- return Object.entries(formData)
3008
- .filter(([_, { statePath: s }]) => s === statePath) // eslint-disable-line @typescript-eslint/no-unused-vars
3009
- .every(([_, { isValid }]) => isValid); // eslint-disable-line @typescript-eslint/no-unused-vars
3010
- }
3011
- /** @internal */
3012
- const getValuesAreValidReadable = statePath => ({
3013
- subscribe(callback) {
3014
- return formData.subscribe(formData => identifyFormData.subscribe(identifyFormData => {
3015
- const valuesAreValid = validateFormData(formData, statePath) && validateFormData(identifyFormData, statePath);
3016
- callback(valuesAreValid);
3017
- }));
3018
- },
3019
- });
3020
- function formDataToEventValues(campaignId, formData) {
3021
- const questions = [];
3022
- const answersMap = {};
3023
- Object.entries(formData).forEach(([name, dataItem]) => {
3024
- questions.push(name);
3025
- const value = dataItem.value;
3026
- const answerKey = `question_${name}`;
3027
- if (Array.isArray(value)) {
3028
- answersMap[answerKey] = {
3029
- choices: value,
3030
- };
3031
- }
3032
- else if (typeof value === 'string') {
3033
- answersMap[answerKey] = {
3034
- free_answer: value,
3035
- };
3036
- }
3037
- });
3038
- return {
3039
- [campaignId]: {
3040
- questions,
3041
- ...answersMap,
3042
- },
3043
- };
3044
- }
3045
- function formDataToIdentifyEventValues(formData) {
3046
- return Object.fromEntries(Object.entries(formData).map(([name, dataItem]) => {
3047
- const value = dataItem.value;
3048
- return [name, value];
3049
- }));
3050
- }
3051
- /** @internal */
3052
- function submit() {
3053
- const systemConfig = getSystem();
3054
- const campaignId = systemConfig.campaignId;
3055
- if (campaignId) {
3056
- const formData$1 = get(formData);
3057
- const identifyFormData$1 = get(identifyFormData);
3058
- const values = formDataToEventValues(campaignId, formData$1);
3059
- const identifyValues = formDataToIdentifyEventValues(identifyFormData$1);
3060
- if (Object.keys(identifyValues).length > 0) {
3061
- identifyValues['user_id'] = getVariables()?.[USER_ID_VARIABLE_NAME];
3062
- }
3063
- return { values, identifyValues };
3064
- }
3065
- return {};
3066
- }
3067
-
3068
3200
  /**
3069
3201
  * モーダル(ポップアップ)のコンポーネントが利用するコードの管理
3070
3202
  */
@@ -11079,4 +11211,4 @@ class ImageBlock extends SvelteComponent {
11079
11211
  }
11080
11212
  }
11081
11213
 
11082
- export { ACTION_HOOK_LABEL, Alignments, AnimationStyles, BackgroundSizes, Box, ClipPaths, CodeElement, Countdown, Cursors, DefaultEdgePosition, DefaultElasticity, DefaultFormButtonColor, DefaultFormIdentifyBooleanField, DefaultFormIdentifyTextField, DefaultListBackground, DefaultListBackgroundNone, DefaultListBackgroundStripe, DefaultListSeparator, DefaultListSeparatorBorder, DefaultListSeparatorGap, DefaultListSeparatorNone, DefaultModalBreakPoint, DefaultModalPlacement, DefaultSlideButton, DefaultSlideNavigationButton, Directions, Elasticities, ElasticityStyle, EmbedElement, Flex, FlexDirections, FlexItem, Fonts, FormCheckBoxes, FormIdentifyBooleanFields, FormIdentifyChoices, FormIdentifyInput, FormIdentifyTextFieldPlaceholders, FormIdentifyTextFieldValidations, FormIdentifyTextFields, FormRadioButtons, FormRatingButtonsFace, FormRatingButtonsNumber, FormSelect, FormTextarea, Grid, GridItem, GridModalState, IconElement, ImageBlock, ImageElement, Justifies, KARTE_MODAL_ROOT, LAYOUT_COMPONENT_NAMES, LengthUnits, List, ListBackgroundTypes, ListDirections, ListItem, ListSeparatorTypes, MediaQueries, Modal, ModalPositions, MovieVimeoElement, MovieYouTubeElement, ObjectFits, OnClickOperationOptions, Overflows, PropTypes, Repeats, SYSTEM_FONT, Slide, SlideItem, State, StateItem, TextBlock, TextButtonBlock, TextButtonElement, TextDirections, TextElement, WritingModes, afterUpdate, applyCss, applyGlobalCss, beforeUpdate, close, closeAction, collection$1 as collection, create, createApp, createFog, destroy, destroyAction, ensureModalRoot, eventHandlers, finalize, formData, getActionRoot, getCssVariables, getEventHandlers, getEvents, getLogs, getState$1 as getState, getStates, getSystem, getVariables, hideOnScroll, hideOnTime, initialize, isOpened, listenLogger, loadActionTable, loadActionTableQuery, loadActionTableRow, loadActionTableRows, loadGlobalScript, loadGlobalStyle, loadStyle, logger, onChangeState, onClose, onCreate, onDestory, onDestroy, onMount, onScroll, onShow, onTime, resetEventHandlers, resetVariables, setEventHandlers, setSetting, setState$1 as setState, setVariables, show, showAction, showModal, showOnScroll, showOnTime, state, tick, variables, widget };
11214
+ export { ACTION_HOOK_LABEL, Alignments, AnimationStyles, BackgroundSizes, Box, ClipPaths, CodeElement, Countdown, Cursors, DefaultEdgePosition, DefaultElasticity, DefaultFormButtonColor, DefaultFormIdentifyBooleanField, DefaultFormIdentifyTextField, DefaultListBackground, DefaultListBackgroundNone, DefaultListBackgroundStripe, DefaultListSeparator, DefaultListSeparatorBorder, DefaultListSeparatorGap, DefaultListSeparatorNone, DefaultModalBreakPoint, DefaultModalPlacement, DefaultSlideButton, DefaultSlideNavigationButton, Directions, Elasticities, ElasticityStyle, EmbedElement, Flex, FlexDirections, FlexItem, Fonts, FormCheckBoxes, FormIdentifyBooleanFields, FormIdentifyChoices, FormIdentifyInput, FormIdentifyTextFieldPlaceholders, FormIdentifyTextFieldValidations, FormIdentifyTextFields, FormRadioButtons, FormRatingButtonsFace, FormRatingButtonsNumber, FormSelect, FormTextarea, Grid, GridItem, GridModalState, IconElement, ImageBlock, ImageElement, Justifies, KARTE_MODAL_ROOT, LAYOUT_COMPONENT_NAMES, LengthUnits, List, ListBackgroundTypes, ListDirections, ListItem, ListSeparatorTypes, MediaQueries, Modal, ModalPositions, MovieVimeoElement, MovieYouTubeElement, ObjectFits, OnClickOperationOptions, Overflows, PropTypes, Repeats, SYSTEM_FONT, Slide, SlideItem, State, StateItem, TextBlock, TextButtonBlock, TextButtonElement, TextDirections, TextElement, WritingModes, addChoiceAnswer, addFreeAnswer, afterUpdate, applyCss, applyGlobalCss, beforeUpdate, close, closeAction, collection$1 as collection, create, createApp, createFog, destroy, destroyAction, ensureModalRoot, eventHandlers, finalize, formData, getActionRoot, getAnsweredQuestion, getAnsweredQuestionIds, getCssVariables, getEventHandlers, getEvents, getLogs, getState$1 as getState, getStates, getSystem, getVariables, hideOnScroll, hideOnTime, initialize, isOpened, listenLogger, loadActionTable, loadActionTableQuery, loadActionTableRow, loadActionTableRows, loadGlobalScript, loadGlobalStyle, loadStyle, logger, onChangeState, onClose, onCreate, onDestory, onDestroy, onMount, onScroll, onShow, onTime, removeAnswer, resetEventHandlers, resetVariables, sendAnswer, sendAnswers, setEventHandlers, setSetting, setState$1 as setState, setVariables, show, showAction, showModal, showOnScroll, showOnTime, state, tick, variables, widget };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plaidev/karte-action-sdk",
3
- "version": "1.1.221",
3
+ "version": "1.1.223",
4
4
  "author": "Plaid Inc.",
5
5
  "license": "Apache-2.0",
6
6
  "module": "./dist/index.es.js",
@@ -56,7 +56,6 @@
56
56
  "devDependencies": {
57
57
  "@microsoft/api-documenter": "7.19.28",
58
58
  "@microsoft/api-extractor": "7.33.8",
59
- "@plaidev/action-compiler": "workspace:*",
60
59
  "@rollup/plugin-alias": "^4.0.0",
61
60
  "@rollup/plugin-commonjs": "^23.0.1",
62
61
  "@rollup/plugin-json": "^5.0.0",
@@ -96,7 +95,14 @@
96
95
  "tsx": "^3.12.3",
97
96
  "typescript": "^4.7.4",
98
97
  "vitepress": "1.0.0-alpha.30",
99
- "vitest": "latest"
98
+ "vitest": "latest",
99
+ "@plaidev/action-compiler": "0.4.231"
100
+ },
101
+ "publishConfig": {
102
+ "access": "public"
103
+ },
104
+ "dependencies": {
105
+ "@rollup/plugin-image": "^3.0.2"
100
106
  },
101
107
  "scripts": {
102
108
  "dev": "tsx ./scripts/preview.ts",
@@ -125,11 +131,5 @@
125
131
  "test:update": "vitest -u",
126
132
  "coverage": "vitest run test --coverage",
127
133
  "icons:update": "tsx ./scripts/update-icons.ts && prettier -w ./src/icons.ts"
128
- },
129
- "publishConfig": {
130
- "access": "public"
131
- },
132
- "dependencies": {
133
- "@rollup/plugin-image": "^3.0.2"
134
134
  }
135
- }
135
+ }