@plaidev/karte-action-sdk 1.1.74 → 1.1.75
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 +159 -18
- package/dist/hydrate/index.es.js +271 -24
- package/dist/index.es.d.ts +159 -18
- package/dist/index.es.js +279 -35
- package/package.json +1 -1
|
@@ -191,7 +191,7 @@ declare const Overflows: string[];
|
|
|
191
191
|
type Overflow = typeof Overflows[number];
|
|
192
192
|
type Style = string;
|
|
193
193
|
type StateName = string;
|
|
194
|
-
//
|
|
194
|
+
// Wrap svelte tools
|
|
195
195
|
type Store<T> = Writable_<T>;
|
|
196
196
|
declare const getStoreState: typeof get_;
|
|
197
197
|
type OPTIONS = {
|
|
@@ -205,16 +205,40 @@ declare const CONSTANTS: {
|
|
|
205
205
|
STATE_EVENT: string;
|
|
206
206
|
};
|
|
207
207
|
declare const actionId: string;
|
|
208
|
-
|
|
208
|
+
declare const ACTION_SHOW_EVENT: string;
|
|
209
|
+
declare const ACTION_CLOSE_EVENT: string;
|
|
210
|
+
declare const ACTION_DESTROY_EVENT: string;
|
|
211
|
+
// Store to handle current state ID
|
|
209
212
|
declare const state: Store<string>;
|
|
210
|
-
//
|
|
213
|
+
// Store to handle all state IDs
|
|
214
|
+
declare const states: Store<string[]>;
|
|
215
|
+
// Store to handle visibility of action
|
|
211
216
|
declare const closed: Store<boolean>;
|
|
212
|
-
//
|
|
217
|
+
// Store to handle max z-index for grid items
|
|
213
218
|
declare const maximumZindex: Store<number>;
|
|
214
|
-
//
|
|
219
|
+
// Store to handle internal event handlers
|
|
220
|
+
declare const internalHandlers: Store<{
|
|
221
|
+
[key: string]: ActionEventHandler;
|
|
222
|
+
}>;
|
|
223
|
+
// Store to handle custom event handlers
|
|
215
224
|
declare const customHandlers: Store<{
|
|
216
225
|
[key: string]: ActionEventHandler;
|
|
217
226
|
}>;
|
|
227
|
+
// Store to handle destruction of action
|
|
228
|
+
declare const destroyed: Store<boolean>;
|
|
229
|
+
// Store to handle stop of action
|
|
230
|
+
declare const stopped: Store<boolean>;
|
|
231
|
+
// Store to handle custom variables
|
|
232
|
+
declare const customVariables: Store<{
|
|
233
|
+
[key: string]: any;
|
|
234
|
+
}>;
|
|
235
|
+
/**
|
|
236
|
+
* {@link setAutoStart} function to set auto start flag.
|
|
237
|
+
*
|
|
238
|
+
* @param {boolean} on
|
|
239
|
+
*/
|
|
240
|
+
declare const setAutoStart: (on?: boolean) => void;
|
|
241
|
+
declare const setState: (event: any) => void;
|
|
218
242
|
declare const initialize: (options?: OPTIONS) => () => void;
|
|
219
243
|
declare const finalize: () => void;
|
|
220
244
|
declare const send_event: (event_name: string, values?: any) => void;
|
|
@@ -273,6 +297,24 @@ declare function customAnimation(node: Element, { transform, animationStyle, del
|
|
|
273
297
|
easing: (t: any) => any;
|
|
274
298
|
css: (progress: number) => string;
|
|
275
299
|
};
|
|
300
|
+
/**
|
|
301
|
+
* {@link loadGlobalScript} load JavaScript that does not support ESM.
|
|
302
|
+
*
|
|
303
|
+
* @param {string} src Link of JavaScript file
|
|
304
|
+
*/
|
|
305
|
+
declare function loadGlobalScript(src: string): Promise<any>;
|
|
306
|
+
/**
|
|
307
|
+
* {@link applyGlobalCss} apply global CSS to WEB page.
|
|
308
|
+
*
|
|
309
|
+
* @param {string} css CSS
|
|
310
|
+
*/
|
|
311
|
+
declare function applyGlobalCss(css: string): Promise<any>;
|
|
312
|
+
/**
|
|
313
|
+
* {@link loadGlobalStyle} load global style to WEB page.
|
|
314
|
+
*
|
|
315
|
+
* @param {string} href Link of style file
|
|
316
|
+
*/
|
|
317
|
+
declare function loadGlobalStyle(href: string): Promise<any>;
|
|
276
318
|
declare const handleFocus: (node: HTMLElement | null) => (e: any) => void;
|
|
277
319
|
declare const setPreviousFocus: () => void;
|
|
278
320
|
declare const handleKeydown: (handlers: {
|
|
@@ -323,28 +365,53 @@ declare function showOnTime<Props extends {
|
|
|
323
365
|
show_on_time?: boolean;
|
|
324
366
|
show_on_time_count?: number;
|
|
325
367
|
}>(props: Props, fn?: Function): (() => void) | null;
|
|
368
|
+
declare const NOOP: Function;
|
|
369
|
+
interface ActionProps<Props, Variables> {
|
|
370
|
+
send: Function;
|
|
371
|
+
data: Props & Variables;
|
|
372
|
+
onShow?: (props: ActionProps<Props, Variables>) => void | Promise<void>;
|
|
373
|
+
onChangeState?: (props: ActionProps<Props, Variables>) => void | Promise<void>;
|
|
374
|
+
}
|
|
326
375
|
/**
|
|
327
|
-
* An options for {@link
|
|
376
|
+
* An options for {@link create}
|
|
328
377
|
*/
|
|
329
|
-
interface
|
|
378
|
+
interface ActionOptions<Props, Variables> {
|
|
330
379
|
/**
|
|
331
|
-
* {@link Send} function to receive events triggered in
|
|
380
|
+
* {@link Send} function to receive events triggered in KARTE action.
|
|
332
381
|
*
|
|
333
382
|
* @default () => {}
|
|
334
383
|
*/
|
|
335
384
|
send?: Function;
|
|
336
385
|
/**
|
|
337
|
-
* {@link Props} used in
|
|
386
|
+
* {@link Props} used in KARTE action.
|
|
338
387
|
*
|
|
339
388
|
* @default {}
|
|
340
389
|
*/
|
|
341
390
|
props?: Props;
|
|
342
391
|
/**
|
|
343
|
-
* {@link Variables} in which user variables or action table used in
|
|
392
|
+
* {@link Variables} in which user variables or action table used in KARTE action.
|
|
344
393
|
*
|
|
345
394
|
* @default {}
|
|
346
395
|
*/
|
|
347
396
|
variables?: Variables;
|
|
397
|
+
/**
|
|
398
|
+
* {@link onShow} function to hook the phase of showing action in KARTE action.
|
|
399
|
+
*
|
|
400
|
+
* @default () => {}
|
|
401
|
+
*/
|
|
402
|
+
onShow?: (props: ActionProps<Props, Variables>) => void | Promise<void>;
|
|
403
|
+
/**
|
|
404
|
+
* {@link onClose} function to hook the phase of closing action in KARTE action.
|
|
405
|
+
*
|
|
406
|
+
* @default () => {}
|
|
407
|
+
*/
|
|
408
|
+
onClose?: (props: ActionProps<Props, Variables>) => void | Promise<void>;
|
|
409
|
+
/**
|
|
410
|
+
* {@link onClose} function to hook the phase of changing action state in KARTE action.
|
|
411
|
+
*
|
|
412
|
+
* @default () => {}
|
|
413
|
+
*/
|
|
414
|
+
onChangeState?: (props: ActionProps<Props, Variables>, newState: string) => void | Promise<void>;
|
|
348
415
|
}
|
|
349
416
|
// types of props to reference for internaly
|
|
350
417
|
interface _Props {
|
|
@@ -361,17 +428,74 @@ interface _Props {
|
|
|
361
428
|
show_on_time_count?: number;
|
|
362
429
|
}
|
|
363
430
|
/**
|
|
364
|
-
*
|
|
431
|
+
* Create the KARTE action
|
|
365
432
|
*
|
|
366
433
|
* @param App - An entry point of svelte component.
|
|
367
|
-
* @param options - A {@link
|
|
434
|
+
* @param options - A {@link ActionOptions | options}
|
|
368
435
|
*
|
|
369
|
-
* @return A function to
|
|
436
|
+
* @return A function to destroy KARTE action
|
|
370
437
|
*/
|
|
371
|
-
declare function
|
|
372
|
-
|
|
438
|
+
declare function create<Props extends _Props, Variables>(App: typeof SvelteComponentDev, options?: ActionOptions<Props, Variables>): () => void;
|
|
439
|
+
/**
|
|
440
|
+
* Dispatch the event to destroy KARTE action
|
|
441
|
+
*/
|
|
442
|
+
declare function dispatchDestroyEvent(): void;
|
|
443
|
+
/**
|
|
444
|
+
* Destory KARTE action
|
|
445
|
+
*/
|
|
446
|
+
declare function destroy(): void;
|
|
447
|
+
/**
|
|
448
|
+
* Show KARTE action
|
|
449
|
+
*/
|
|
450
|
+
declare function show(): void;
|
|
451
|
+
/**
|
|
452
|
+
* Close KARTE action
|
|
453
|
+
*/
|
|
454
|
+
declare function close(): void;
|
|
455
|
+
declare const KARTE_ACTION_ROOT = "karte-modal-root";
|
|
373
456
|
declare const KARTE_ACTION_RID = "karte-action-rid";
|
|
374
|
-
declare function
|
|
457
|
+
declare function ensureActionRoot(useShadow?: boolean): ShadowRoot | HTMLElement;
|
|
458
|
+
/**
|
|
459
|
+
* {@link onShow} function to set the function to hook the phase after showing action.
|
|
460
|
+
*
|
|
461
|
+
* @param {(props: ActionProps<Props, Variables>) => void | Promise<void>} fn Callback
|
|
462
|
+
*/
|
|
463
|
+
declare function onShow<Props extends _Props, Variables>(/**
|
|
464
|
+
* @param {ActionProps<Props, Variables>} props Properties of KARTE action
|
|
465
|
+
* @returns {void|Promise<void>}
|
|
466
|
+
*/
|
|
467
|
+
fn: (props: ActionProps<Props, Variables>) => void | Promise<void>): void;
|
|
468
|
+
/**
|
|
469
|
+
* {@link onClose} function to set the function to hook the phase before closing action.
|
|
470
|
+
*
|
|
471
|
+
* @param {(props: ActionProps<Props, Variables>) => void | Promise<void>} fn Callback
|
|
472
|
+
*/
|
|
473
|
+
declare function onClose<Props extends _Props, Variables>(/**
|
|
474
|
+
* @param {ActionProps<Props, Variables>} props Properties of KARTE action
|
|
475
|
+
* @returns {void|Promise<void>}
|
|
476
|
+
*/
|
|
477
|
+
fn: (props: ActionProps<Props, Variables>) => void | Promise<void>): void;
|
|
478
|
+
/**
|
|
479
|
+
* {@link onDestory} function to set the function to hook the phase before destroying action.
|
|
480
|
+
*
|
|
481
|
+
* @param {(props: ActionProps<Props, Variables>) => void | Promise<void>} fn Callback
|
|
482
|
+
*/
|
|
483
|
+
declare function onDestroy<Props extends _Props, Variables>(/**
|
|
484
|
+
* @param {ActionProps<Props, Variables>} props Properties of KARTE action
|
|
485
|
+
* @returns {void|Promise<void>}
|
|
486
|
+
*/
|
|
487
|
+
fn: (props: ActionProps<Props, Variables>) => void | Promise<void>): void;
|
|
488
|
+
/**
|
|
489
|
+
* {@link onChangeState} function to set the function to hook the phase after changing action state.
|
|
490
|
+
*
|
|
491
|
+
* @param {(props: ActionProps, newState: string) => void | Promise<void>} fn Callback
|
|
492
|
+
*/
|
|
493
|
+
declare function onChangeState<Props extends _Props, Variables>(/**
|
|
494
|
+
* @param {ActionProps<Props, Variables>} props Properties of KARTE action
|
|
495
|
+
* @param {string} newState New state of KARTE action
|
|
496
|
+
* @returns {void|Promise<void>}
|
|
497
|
+
*/
|
|
498
|
+
fn: (props: ActionProps<Props, Variables>, newState: string) => void | Promise<void>): void;
|
|
375
499
|
declare const h: (type: string, props: any, ...children: Array<any>) => HTMLElement;
|
|
376
500
|
declare function createFog({ color, opacity, zIndex, onclick }: {
|
|
377
501
|
color?: string;
|
|
@@ -384,11 +508,28 @@ declare function createFog({ color, opacity, zIndex, onclick }: {
|
|
|
384
508
|
};
|
|
385
509
|
type EmbedLogic = "replace" | "append" | "prepend" | "after" | "before";
|
|
386
510
|
declare function embed(target: HTMLElement, replace: HTMLElement, embed_method: EmbedLogic): void;
|
|
511
|
+
/**
|
|
512
|
+
* {@link applyCss} apply CSS to KARTE action.
|
|
513
|
+
*
|
|
514
|
+
* @param {string} css CSS
|
|
515
|
+
*/
|
|
516
|
+
declare function applyCss(css: string): Promise<any>;
|
|
517
|
+
/**
|
|
518
|
+
* {@link loadStyle} load global style to KARTE action.
|
|
519
|
+
*
|
|
520
|
+
* @param {string} href Link of style file
|
|
521
|
+
*/
|
|
522
|
+
declare function loadStyle(href: string): Promise<any>;
|
|
523
|
+
// -------- The following codes are deprecated --------
|
|
524
|
+
declare const showModal: typeof create; // @deprecated
|
|
525
|
+
type ModalOptions<Props, Variables> = ActionOptions<Props, Variables>; // @deprecated
|
|
526
|
+
declare const KARTE_MODAL_ROOT = "karte-modal-root"; // @deprecated
|
|
527
|
+
declare const ensureModalRoot: typeof ensureActionRoot; // @deprecated
|
|
387
528
|
/**
|
|
388
529
|
* An options for {@link createApp}
|
|
389
530
|
* @deprecated
|
|
390
531
|
*/
|
|
391
|
-
type AppOptions<Props, Variables> =
|
|
532
|
+
type AppOptions<Props, Variables> = ActionOptions<Props, Variables>;
|
|
392
533
|
/**
|
|
393
534
|
* App application instance that is with {@link createApp}
|
|
394
535
|
* @deprecated
|
|
@@ -428,7 +569,7 @@ declare const collection: (config: {
|
|
|
428
569
|
} | null | undefined, cb: (err: Error | null, items?: any) => void): void;
|
|
429
570
|
set(key: string, value: string, cb: (err: Error | null) => void): void;
|
|
430
571
|
};
|
|
431
|
-
export { Store, getStoreState, ActionEventHandler, CONSTANTS, actionId, state, closed, maximumZindex, customHandlers, initialize, finalize, send_event, isPreview, setMiximumZindex, none, moveTo, linkTo, closeApp, runScript, execOnClickOperation, haveFunction, customAnimation, handleFocus, setPreviousFocus, handleKeydown, getPositionStyle, getTransform, getMarginStyle, onScroll, onTime, hasSuffix, toBr, randStr, PropTypes, PropType, Code, MediaQueries, MediaQuery, Directions, Direction, AnimationStyles, AnimationStyle, ModalPositions, ModalPosition, ModalMargin, ModalPlacement, DefaultModalPlacement, OperationArgumentType, Operation, OnClickOperationOptions, OnClickOperation, LongText, Url, Image, LengthUnits, LengthUnit, Length, Color, Justifies, Justify, Alignments, Alignment, ObjectFits, ObjectFit, Repeats, Repeat, BackgroundSizes, BackgroundSize, Cursors, Cursor, Overflows, Overflow, Style, StateName, hideOnScroll, hideOnTime, showOnScroll, showOnTime,
|
|
572
|
+
export { Store, getStoreState, ActionEventHandler, CONSTANTS, actionId, ACTION_SHOW_EVENT, ACTION_CLOSE_EVENT, ACTION_DESTROY_EVENT, state, states, closed, maximumZindex, internalHandlers, customHandlers, destroyed, stopped, customVariables, setAutoStart, setState, initialize, finalize, send_event, isPreview, setMiximumZindex, none, moveTo, linkTo, closeApp, runScript, execOnClickOperation, haveFunction, customAnimation, loadGlobalScript, applyGlobalCss, loadGlobalStyle, handleFocus, setPreviousFocus, handleKeydown, getPositionStyle, getTransform, getMarginStyle, onScroll, onTime, hasSuffix, toBr, randStr, PropTypes, PropType, Code, MediaQueries, MediaQuery, Directions, Direction, AnimationStyles, AnimationStyle, ModalPositions, ModalPosition, ModalMargin, ModalPlacement, DefaultModalPlacement, OperationArgumentType, Operation, OnClickOperationOptions, OnClickOperation, LongText, Url, Image, LengthUnits, LengthUnit, Length, Color, Justifies, Justify, Alignments, Alignment, ObjectFits, ObjectFit, Repeats, Repeat, BackgroundSizes, BackgroundSize, Cursors, Cursor, Overflows, Overflow, Style, StateName, hideOnScroll, hideOnTime, showOnScroll, showOnTime, NOOP, ActionProps, ActionOptions, create, dispatchDestroyEvent, destroy, show, close, KARTE_ACTION_ROOT, KARTE_ACTION_RID, ensureActionRoot, onShow, onClose, onDestroy, onChangeState, h, createFog, EmbedLogic, embed, applyCss, loadStyle, showModal, ModalOptions, KARTE_MODAL_ROOT, ensureModalRoot, AppOptions, App, createApp, collection };
|
|
432
573
|
export { default as State } from './components/State.svelte';
|
|
433
574
|
export { default as StateItem } from './components/StateItem.svelte';
|
|
434
575
|
export { default as Modal } from './components/Modal.svelte';
|
package/dist/hydrate/index.es.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { writable, get } from 'svelte/store';
|
|
2
2
|
import 'svelte/easing';
|
|
3
3
|
import { SvelteComponent, init, safe_not_equal, append_styles, create_slot, create_component, space, claim_component, claim_space, mount_component, insert_hydration, update_slot_base, get_all_dirty_from_scope, get_slot_changes, transition_in, transition_out, destroy_component, detach, empty, group_outros, check_outros, component_subscribe, noop, element, claim_element, children, attr, listen, is_function, append_hydration, add_render_callback, create_in_transition, svg_element, claim_svg_element, binding_callbacks, destroy_each, text, claim_text, set_data, src_url_equal, null_to_empty } from 'https://esm.sh/svelte@3.53.1/internal';
|
|
4
|
-
import { createEventDispatcher, onMount, onDestroy, setContext, getContext } from 'https://esm.sh/svelte@3.53.1';
|
|
4
|
+
import { createEventDispatcher, onMount, onDestroy as onDestroy$1, setContext, getContext } from 'https://esm.sh/svelte@3.53.1';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* 内部的に使われている、UIから選択できない関数
|
|
@@ -139,21 +139,41 @@ const CONSTANTS = {
|
|
|
139
139
|
};
|
|
140
140
|
const functionOptions = writable({});
|
|
141
141
|
const actionId = randStr();
|
|
142
|
-
|
|
142
|
+
const ACTION_SHOW_EVENT = `KARTE-ACTION-SHOW-${actionId}`;
|
|
143
|
+
const ACTION_CLOSE_EVENT = `KARTE-ACTION-CLOSE-${actionId}`;
|
|
144
|
+
const ACTION_DESTROY_EVENT = `KARTE-ACTION-DESTROY-${actionId}`;
|
|
145
|
+
// Store to handle current state ID
|
|
143
146
|
const state = writable('/');
|
|
144
|
-
//
|
|
147
|
+
// Store to handle all state IDs
|
|
148
|
+
const states = writable([]);
|
|
149
|
+
// Store to handle visibility of action
|
|
145
150
|
const closed = writable(false);
|
|
146
|
-
//
|
|
151
|
+
// Store to handle max z-index for grid items
|
|
147
152
|
const maximumZindex = writable(0);
|
|
148
|
-
//
|
|
153
|
+
// Store to handle internal event handlers
|
|
154
|
+
const internalHandlers = writable({});
|
|
155
|
+
// Store to handle custom event handlers
|
|
149
156
|
const customHandlers = writable({});
|
|
157
|
+
// Store to handle destruction of action
|
|
158
|
+
const destroyed = writable(false);
|
|
159
|
+
// Store to handle stop of action
|
|
160
|
+
const stopped = writable(false);
|
|
161
|
+
// Store to handle custom variables
|
|
162
|
+
const customVariables = writable({});
|
|
163
|
+
/**
|
|
164
|
+
* {@link setAutoStart} function to set auto start flag.
|
|
165
|
+
*
|
|
166
|
+
* @param {boolean} on
|
|
167
|
+
*/
|
|
168
|
+
const setAutoStart = (on = true) => {
|
|
169
|
+
stopped.set(!on);
|
|
170
|
+
};
|
|
150
171
|
const setState = (event) => {
|
|
151
172
|
if (event.detail.actionId === actionId || event.detail.actionId === CONSTANTS.ALL_ACTION_ID) {
|
|
152
173
|
state.set(event.detail.to);
|
|
153
174
|
}
|
|
154
175
|
};
|
|
155
176
|
const initialize = (options) => {
|
|
156
|
-
window.addEventListener(CONSTANTS.STATE_EVENT, setState);
|
|
157
177
|
if (options?.initialState) {
|
|
158
178
|
state.set(options?.initialState);
|
|
159
179
|
}
|
|
@@ -162,7 +182,6 @@ const initialize = (options) => {
|
|
|
162
182
|
return () => finalize();
|
|
163
183
|
};
|
|
164
184
|
const finalize = () => {
|
|
165
|
-
window.removeEventListener(CONSTANTS.STATE_EVENT, setState);
|
|
166
185
|
functionOptions.set({});
|
|
167
186
|
};
|
|
168
187
|
const send_event = (event_name, values) => {
|
|
@@ -236,6 +255,49 @@ function customAnimation(node, { transform, animationStyle, delay = 0, duration
|
|
|
236
255
|
return {};
|
|
237
256
|
}
|
|
238
257
|
}
|
|
258
|
+
/**
|
|
259
|
+
* {@link loadGlobalScript} load JavaScript that does not support ESM.
|
|
260
|
+
*
|
|
261
|
+
* @param {string} src Link of JavaScript file
|
|
262
|
+
*/
|
|
263
|
+
async function loadGlobalScript(src) {
|
|
264
|
+
return new Promise((resolve, reject) => {
|
|
265
|
+
const script = document.createElement('script');
|
|
266
|
+
script.src = src;
|
|
267
|
+
document.body.appendChild(script);
|
|
268
|
+
script.addEventListener('load', () => resolve(script));
|
|
269
|
+
script.addEventListener('error', () => reject(script));
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* {@link applyGlobalCss} apply global CSS to WEB page.
|
|
274
|
+
*
|
|
275
|
+
* @param {string} css CSS
|
|
276
|
+
*/
|
|
277
|
+
async function applyGlobalCss(css) {
|
|
278
|
+
return new Promise((resolve, reject) => {
|
|
279
|
+
const style = document.createElement('style');
|
|
280
|
+
style.textContent = css;
|
|
281
|
+
document.body.appendChild(style);
|
|
282
|
+
style.addEventListener('load', () => resolve(style));
|
|
283
|
+
style.addEventListener('error', () => reject(style));
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* {@link loadGlobalStyle} load global style to WEB page.
|
|
288
|
+
*
|
|
289
|
+
* @param {string} href Link of style file
|
|
290
|
+
*/
|
|
291
|
+
async function loadGlobalStyle(href) {
|
|
292
|
+
return new Promise((resolve, reject) => {
|
|
293
|
+
const link = document.createElement('link');
|
|
294
|
+
link.rel = 'stylesheet';
|
|
295
|
+
link.href = href;
|
|
296
|
+
document.body.appendChild(link);
|
|
297
|
+
link.addEventListener('load', () => resolve(link));
|
|
298
|
+
link.addEventListener('error', () => reject(link));
|
|
299
|
+
});
|
|
300
|
+
}
|
|
239
301
|
|
|
240
302
|
const PropTypes = [
|
|
241
303
|
'BooleanKeyword',
|
|
@@ -376,58 +438,121 @@ function showOnTime(props, fn) {
|
|
|
376
438
|
: null;
|
|
377
439
|
}
|
|
378
440
|
|
|
441
|
+
const NOOP = (_args) => { };
|
|
379
442
|
/**
|
|
380
|
-
*
|
|
443
|
+
* Create the KARTE action
|
|
381
444
|
*
|
|
382
445
|
* @param App - An entry point of svelte component.
|
|
383
|
-
* @param options - A {@link
|
|
446
|
+
* @param options - A {@link ActionOptions | options}
|
|
384
447
|
*
|
|
385
|
-
* @return A function to
|
|
448
|
+
* @return A function to destroy KARTE action
|
|
386
449
|
*/
|
|
387
|
-
function
|
|
450
|
+
function create(App, options = {
|
|
388
451
|
send: () => { },
|
|
389
452
|
props: {},
|
|
390
453
|
variables: {},
|
|
391
454
|
}) {
|
|
392
455
|
let app = null;
|
|
456
|
+
const data = { ...options.props, ...options.variables };
|
|
393
457
|
const close = () => {
|
|
394
|
-
if (app) {
|
|
395
|
-
|
|
396
|
-
|
|
458
|
+
if (!app) {
|
|
459
|
+
return;
|
|
460
|
+
}
|
|
461
|
+
closed.set(true);
|
|
462
|
+
window.removeEventListener(CONSTANTS.STATE_EVENT, setState);
|
|
463
|
+
if (options.onClose) {
|
|
464
|
+
options.onClose({ send: options.send, data });
|
|
397
465
|
}
|
|
466
|
+
app.$destroy();
|
|
467
|
+
app = null;
|
|
398
468
|
};
|
|
469
|
+
window.addEventListener(ACTION_CLOSE_EVENT, close);
|
|
399
470
|
const show = () => {
|
|
400
471
|
if (app) {
|
|
401
472
|
return;
|
|
402
473
|
}
|
|
403
474
|
options.send('message_open');
|
|
475
|
+
closed.set(false);
|
|
476
|
+
window.addEventListener(CONSTANTS.STATE_EVENT, setState);
|
|
404
477
|
app = new App({
|
|
405
478
|
target: ensureModalRoot(!true),
|
|
406
479
|
hydrate: true,
|
|
407
480
|
props: {
|
|
408
481
|
send: options.send,
|
|
409
482
|
close,
|
|
410
|
-
data
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
},
|
|
483
|
+
data,
|
|
484
|
+
onShow: options.onShow,
|
|
485
|
+
onChangeState: options.onChangeState,
|
|
414
486
|
},
|
|
415
487
|
});
|
|
416
488
|
};
|
|
489
|
+
window.addEventListener(ACTION_SHOW_EVENT, show);
|
|
490
|
+
const startClose = () => {
|
|
491
|
+
let cleanup;
|
|
492
|
+
// if in hydrate mode (preview), nothing is done, since action will be disposed and closed in the preview module
|
|
493
|
+
{
|
|
494
|
+
cleanup = NOOP;
|
|
495
|
+
}
|
|
496
|
+
return cleanup;
|
|
497
|
+
};
|
|
417
498
|
const _show = () => {
|
|
418
499
|
show();
|
|
419
500
|
return close;
|
|
420
501
|
};
|
|
421
|
-
|
|
422
|
-
|
|
502
|
+
const startShow = () => {
|
|
503
|
+
let cleanup;
|
|
504
|
+
// if in hydrate mode (preview), always show action
|
|
505
|
+
{
|
|
506
|
+
cleanup = _show();
|
|
507
|
+
}
|
|
508
|
+
return cleanup;
|
|
509
|
+
};
|
|
510
|
+
// init
|
|
511
|
+
let hideCleanup = NOOP;
|
|
512
|
+
let showCleanup = NOOP;
|
|
513
|
+
if (!getStoreState(stopped)) {
|
|
514
|
+
hideCleanup = startShow();
|
|
515
|
+
showCleanup = startClose();
|
|
516
|
+
}
|
|
423
517
|
return () => {
|
|
424
518
|
close();
|
|
519
|
+
hideCleanup();
|
|
425
520
|
showCleanup();
|
|
521
|
+
window.removeEventListener(ACTION_SHOW_EVENT, show);
|
|
522
|
+
window.removeEventListener(ACTION_CLOSE_EVENT, close);
|
|
426
523
|
};
|
|
427
524
|
}
|
|
428
|
-
|
|
525
|
+
/**
|
|
526
|
+
* Dispatch the event to destroy KARTE action
|
|
527
|
+
*/
|
|
528
|
+
function dispatchDestroyEvent() {
|
|
529
|
+
const event = new Event(ACTION_DESTROY_EVENT);
|
|
530
|
+
window.dispatchEvent(event);
|
|
531
|
+
}
|
|
532
|
+
/**
|
|
533
|
+
* Destory KARTE action
|
|
534
|
+
*/
|
|
535
|
+
function destroy() {
|
|
536
|
+
destroyed.set(true);
|
|
537
|
+
dispatchDestroyEvent();
|
|
538
|
+
}
|
|
539
|
+
/**
|
|
540
|
+
* Show KARTE action
|
|
541
|
+
*/
|
|
542
|
+
function show() {
|
|
543
|
+
const event = new Event(ACTION_SHOW_EVENT);
|
|
544
|
+
window.dispatchEvent(event);
|
|
545
|
+
}
|
|
546
|
+
/**
|
|
547
|
+
* Close KARTE action
|
|
548
|
+
*/
|
|
549
|
+
function close() {
|
|
550
|
+
const event = new Event(ACTION_CLOSE_EVENT);
|
|
551
|
+
window.dispatchEvent(event);
|
|
552
|
+
}
|
|
553
|
+
const KARTE_ACTION_ROOT = 'karte-modal-root';
|
|
429
554
|
const KARTE_ACTION_RID = 'karte-action-rid';
|
|
430
|
-
function
|
|
555
|
+
function ensureActionRoot(useShadow = true) {
|
|
431
556
|
let el = document.querySelector(`.${KARTE_MODAL_ROOT}[data-${KARTE_ACTION_RID}='${actionId}']`);
|
|
432
557
|
if (el == null) {
|
|
433
558
|
el = h('div', { class: KARTE_MODAL_ROOT, [`data-${KARTE_ACTION_RID}`]: actionId });
|
|
@@ -441,6 +566,71 @@ function ensureModalRoot(useShadow = true) {
|
|
|
441
566
|
return el;
|
|
442
567
|
}
|
|
443
568
|
}
|
|
569
|
+
/**
|
|
570
|
+
* {@link onShow} function to set the function to hook the phase after showing action.
|
|
571
|
+
*
|
|
572
|
+
* @param {(props: ActionProps<Props, Variables>) => void | Promise<void>} fn Callback
|
|
573
|
+
*/
|
|
574
|
+
function onShow(
|
|
575
|
+
/**
|
|
576
|
+
* @param {ActionProps<Props, Variables>} props Properties of KARTE action
|
|
577
|
+
* @returns {void|Promise<void>}
|
|
578
|
+
*/
|
|
579
|
+
fn) {
|
|
580
|
+
internalHandlers.update(current => {
|
|
581
|
+
current.onShow = fn;
|
|
582
|
+
return current;
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
/**
|
|
586
|
+
* {@link onClose} function to set the function to hook the phase before closing action.
|
|
587
|
+
*
|
|
588
|
+
* @param {(props: ActionProps<Props, Variables>) => void | Promise<void>} fn Callback
|
|
589
|
+
*/
|
|
590
|
+
function onClose(
|
|
591
|
+
/**
|
|
592
|
+
* @param {ActionProps<Props, Variables>} props Properties of KARTE action
|
|
593
|
+
* @returns {void|Promise<void>}
|
|
594
|
+
*/
|
|
595
|
+
fn) {
|
|
596
|
+
internalHandlers.update(current => {
|
|
597
|
+
current.onClose = fn;
|
|
598
|
+
return current;
|
|
599
|
+
});
|
|
600
|
+
}
|
|
601
|
+
/**
|
|
602
|
+
* {@link onDestory} function to set the function to hook the phase before destroying action.
|
|
603
|
+
*
|
|
604
|
+
* @param {(props: ActionProps<Props, Variables>) => void | Promise<void>} fn Callback
|
|
605
|
+
*/
|
|
606
|
+
function onDestroy(
|
|
607
|
+
/**
|
|
608
|
+
* @param {ActionProps<Props, Variables>} props Properties of KARTE action
|
|
609
|
+
* @returns {void|Promise<void>}
|
|
610
|
+
*/
|
|
611
|
+
fn) {
|
|
612
|
+
internalHandlers.update(current => {
|
|
613
|
+
current.onDestroy = fn;
|
|
614
|
+
return current;
|
|
615
|
+
});
|
|
616
|
+
}
|
|
617
|
+
/**
|
|
618
|
+
* {@link onChangeState} function to set the function to hook the phase after changing action state.
|
|
619
|
+
*
|
|
620
|
+
* @param {(props: ActionProps, newState: string) => void | Promise<void>} fn Callback
|
|
621
|
+
*/
|
|
622
|
+
function onChangeState(
|
|
623
|
+
/**
|
|
624
|
+
* @param {ActionProps<Props, Variables>} props Properties of KARTE action
|
|
625
|
+
* @param {string} newState New state of KARTE action
|
|
626
|
+
* @returns {void|Promise<void>}
|
|
627
|
+
*/
|
|
628
|
+
fn) {
|
|
629
|
+
internalHandlers.update(current => {
|
|
630
|
+
current.onChangeState = fn;
|
|
631
|
+
return current;
|
|
632
|
+
});
|
|
633
|
+
}
|
|
444
634
|
const h = (type, props, ...children) => {
|
|
445
635
|
const el = document.createElement(type);
|
|
446
636
|
for (const key of Object.keys(props)) {
|
|
@@ -501,6 +691,52 @@ function embed(target, replace, embed_method) {
|
|
|
501
691
|
target.before(replace);
|
|
502
692
|
}
|
|
503
693
|
}
|
|
694
|
+
function getActionShadowRoot() {
|
|
695
|
+
const root = document.querySelector(`.${KARTE_ACTION_ROOT}[data-${KARTE_ACTION_RID}='${actionId}']`);
|
|
696
|
+
if (!root || !root.shadowRoot) {
|
|
697
|
+
return null;
|
|
698
|
+
}
|
|
699
|
+
return root.shadowRoot;
|
|
700
|
+
}
|
|
701
|
+
/**
|
|
702
|
+
* {@link applyCss} apply CSS to KARTE action.
|
|
703
|
+
*
|
|
704
|
+
* @param {string} css CSS
|
|
705
|
+
*/
|
|
706
|
+
async function applyCss(css) {
|
|
707
|
+
return new Promise((resolve, reject) => {
|
|
708
|
+
const style = document.createElement('style');
|
|
709
|
+
style.textContent = css;
|
|
710
|
+
const shadowRoot = getActionShadowRoot();
|
|
711
|
+
if (!shadowRoot)
|
|
712
|
+
return;
|
|
713
|
+
shadowRoot.append(style);
|
|
714
|
+
style.addEventListener('load', () => resolve(style));
|
|
715
|
+
style.addEventListener('error', () => reject(style));
|
|
716
|
+
});
|
|
717
|
+
}
|
|
718
|
+
/**
|
|
719
|
+
* {@link loadStyle} load global style to KARTE action.
|
|
720
|
+
*
|
|
721
|
+
* @param {string} href Link of style file
|
|
722
|
+
*/
|
|
723
|
+
async function loadStyle(href) {
|
|
724
|
+
return new Promise((resolve, reject) => {
|
|
725
|
+
const link = document.createElement('link');
|
|
726
|
+
link.rel = 'stylesheet';
|
|
727
|
+
link.href = href;
|
|
728
|
+
const shadowRoot = getActionShadowRoot();
|
|
729
|
+
if (!shadowRoot)
|
|
730
|
+
return;
|
|
731
|
+
shadowRoot.append(link);
|
|
732
|
+
link.addEventListener('load', () => resolve(link));
|
|
733
|
+
link.addEventListener('error', () => reject(link));
|
|
734
|
+
});
|
|
735
|
+
}
|
|
736
|
+
// -------- The following codes are deprecated --------
|
|
737
|
+
const showModal = create; // @deprecated
|
|
738
|
+
const KARTE_MODAL_ROOT = KARTE_ACTION_ROOT; // @deprecated
|
|
739
|
+
const ensureModalRoot = ensureActionRoot; // @deprecated
|
|
504
740
|
/**
|
|
505
741
|
* Create an application instance
|
|
506
742
|
* @deprecated
|
|
@@ -831,6 +1067,17 @@ function instance$e($$self, $$props, $$invalidate) {
|
|
|
831
1067
|
if ('$$scope' in $$props) $$invalidate(2, $$scope = $$props.$$scope);
|
|
832
1068
|
};
|
|
833
1069
|
|
|
1070
|
+
$$self.$$.update = () => {
|
|
1071
|
+
if ($$self.$$.dirty & /*path*/ 1) {
|
|
1072
|
+
{
|
|
1073
|
+
states.update(current => {
|
|
1074
|
+
current.push(path);
|
|
1075
|
+
return current;
|
|
1076
|
+
});
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
};
|
|
1080
|
+
|
|
834
1081
|
return [path, $state, $$scope, slots];
|
|
835
1082
|
}
|
|
836
1083
|
|
|
@@ -1295,7 +1542,7 @@ function instance$c($$self, $$props, $$invalidate) {
|
|
|
1295
1542
|
$$invalidate(6, visible = true);
|
|
1296
1543
|
});
|
|
1297
1544
|
|
|
1298
|
-
onDestroy(() => setPreviousFocus());
|
|
1545
|
+
onDestroy$1(() => setPreviousFocus());
|
|
1299
1546
|
|
|
1300
1547
|
function div_binding($$value) {
|
|
1301
1548
|
binding_callbacks[$$value ? 'unshift' : 'push'](() => {
|
|
@@ -3220,4 +3467,4 @@ class ImageBlock extends SvelteComponent {
|
|
|
3220
3467
|
}
|
|
3221
3468
|
}
|
|
3222
3469
|
|
|
3223
|
-
export { Alignments, AnimationStyles, BackgroundSizes, CONSTANTS, Cursors, DefaultModalPlacement, Directions, Flex, FlexItem, Grid, GridItem, GridModalState, ImageBlock, ImageElement, Justifies, KARTE_ACTION_RID, KARTE_MODAL_ROOT, LengthUnits, MediaQueries, Modal, ModalPositions, ObjectFits, OnClickOperationOptions, Overflows, PropTypes, Repeats, State, StateItem, TextBlock, TextButtonBlock, TextButtonElement, TextElement, actionId, closeApp, closed, collection, createApp, createFog, customAnimation, customHandlers, embed, ensureModalRoot, execOnClickOperation, finalize, getMarginStyle, getPositionStyle, getStoreState, getTransform, h, handleFocus, handleKeydown, hasSuffix, haveFunction, hideOnScroll, hideOnTime, initialize, isPreview, linkTo, maximumZindex, moveTo, none, onScroll, onTime, randStr, runScript, send_event, setMiximumZindex, setPreviousFocus, showModal, showOnScroll, showOnTime, state, toBr };
|
|
3470
|
+
export { ACTION_CLOSE_EVENT, ACTION_DESTROY_EVENT, ACTION_SHOW_EVENT, Alignments, AnimationStyles, BackgroundSizes, CONSTANTS, Cursors, DefaultModalPlacement, Directions, Flex, FlexItem, Grid, GridItem, GridModalState, ImageBlock, ImageElement, Justifies, KARTE_ACTION_RID, KARTE_ACTION_ROOT, KARTE_MODAL_ROOT, LengthUnits, MediaQueries, Modal, ModalPositions, NOOP, ObjectFits, OnClickOperationOptions, Overflows, PropTypes, Repeats, State, StateItem, TextBlock, TextButtonBlock, TextButtonElement, TextElement, actionId, applyCss, applyGlobalCss, close, closeApp, closed, collection, create, createApp, createFog, customAnimation, customHandlers, customVariables, destroy, destroyed, dispatchDestroyEvent, embed, ensureActionRoot, ensureModalRoot, execOnClickOperation, finalize, getMarginStyle, getPositionStyle, getStoreState, getTransform, h, handleFocus, handleKeydown, hasSuffix, haveFunction, hideOnScroll, hideOnTime, initialize, internalHandlers, isPreview, linkTo, loadGlobalScript, loadGlobalStyle, loadStyle, maximumZindex, moveTo, none, onChangeState, onClose, onDestroy, onScroll, onShow, onTime, randStr, runScript, send_event, setAutoStart, setMiximumZindex, setPreviousFocus, setState, show, showModal, showOnScroll, showOnTime, state, states, stopped, toBr };
|
package/dist/index.es.d.ts
CHANGED
|
@@ -191,7 +191,7 @@ declare const Overflows: string[];
|
|
|
191
191
|
type Overflow = typeof Overflows[number];
|
|
192
192
|
type Style = string;
|
|
193
193
|
type StateName = string;
|
|
194
|
-
//
|
|
194
|
+
// Wrap svelte tools
|
|
195
195
|
type Store<T> = Writable_<T>;
|
|
196
196
|
declare const getStoreState: typeof get_;
|
|
197
197
|
type OPTIONS = {
|
|
@@ -205,16 +205,40 @@ declare const CONSTANTS: {
|
|
|
205
205
|
STATE_EVENT: string;
|
|
206
206
|
};
|
|
207
207
|
declare const actionId: string;
|
|
208
|
-
|
|
208
|
+
declare const ACTION_SHOW_EVENT: string;
|
|
209
|
+
declare const ACTION_CLOSE_EVENT: string;
|
|
210
|
+
declare const ACTION_DESTROY_EVENT: string;
|
|
211
|
+
// Store to handle current state ID
|
|
209
212
|
declare const state: Store<string>;
|
|
210
|
-
//
|
|
213
|
+
// Store to handle all state IDs
|
|
214
|
+
declare const states: Store<string[]>;
|
|
215
|
+
// Store to handle visibility of action
|
|
211
216
|
declare const closed: Store<boolean>;
|
|
212
|
-
//
|
|
217
|
+
// Store to handle max z-index for grid items
|
|
213
218
|
declare const maximumZindex: Store<number>;
|
|
214
|
-
//
|
|
219
|
+
// Store to handle internal event handlers
|
|
220
|
+
declare const internalHandlers: Store<{
|
|
221
|
+
[key: string]: ActionEventHandler;
|
|
222
|
+
}>;
|
|
223
|
+
// Store to handle custom event handlers
|
|
215
224
|
declare const customHandlers: Store<{
|
|
216
225
|
[key: string]: ActionEventHandler;
|
|
217
226
|
}>;
|
|
227
|
+
// Store to handle destruction of action
|
|
228
|
+
declare const destroyed: Store<boolean>;
|
|
229
|
+
// Store to handle stop of action
|
|
230
|
+
declare const stopped: Store<boolean>;
|
|
231
|
+
// Store to handle custom variables
|
|
232
|
+
declare const customVariables: Store<{
|
|
233
|
+
[key: string]: any;
|
|
234
|
+
}>;
|
|
235
|
+
/**
|
|
236
|
+
* {@link setAutoStart} function to set auto start flag.
|
|
237
|
+
*
|
|
238
|
+
* @param {boolean} on
|
|
239
|
+
*/
|
|
240
|
+
declare const setAutoStart: (on?: boolean) => void;
|
|
241
|
+
declare const setState: (event: any) => void;
|
|
218
242
|
declare const initialize: (options?: OPTIONS) => () => void;
|
|
219
243
|
declare const finalize: () => void;
|
|
220
244
|
declare const send_event: (event_name: string, values?: any) => void;
|
|
@@ -273,6 +297,24 @@ declare function customAnimation(node: Element, { transform, animationStyle, del
|
|
|
273
297
|
easing: (t: any) => any;
|
|
274
298
|
css: (progress: number) => string;
|
|
275
299
|
};
|
|
300
|
+
/**
|
|
301
|
+
* {@link loadGlobalScript} load JavaScript that does not support ESM.
|
|
302
|
+
*
|
|
303
|
+
* @param {string} src Link of JavaScript file
|
|
304
|
+
*/
|
|
305
|
+
declare function loadGlobalScript(src: string): Promise<any>;
|
|
306
|
+
/**
|
|
307
|
+
* {@link applyGlobalCss} apply global CSS to WEB page.
|
|
308
|
+
*
|
|
309
|
+
* @param {string} css CSS
|
|
310
|
+
*/
|
|
311
|
+
declare function applyGlobalCss(css: string): Promise<any>;
|
|
312
|
+
/**
|
|
313
|
+
* {@link loadGlobalStyle} load global style to WEB page.
|
|
314
|
+
*
|
|
315
|
+
* @param {string} href Link of style file
|
|
316
|
+
*/
|
|
317
|
+
declare function loadGlobalStyle(href: string): Promise<any>;
|
|
276
318
|
declare const handleFocus: (node: HTMLElement | null) => (e: any) => void;
|
|
277
319
|
declare const setPreviousFocus: () => void;
|
|
278
320
|
declare const handleKeydown: (handlers: {
|
|
@@ -323,28 +365,53 @@ declare function showOnTime<Props extends {
|
|
|
323
365
|
show_on_time?: boolean;
|
|
324
366
|
show_on_time_count?: number;
|
|
325
367
|
}>(props: Props, fn?: Function): (() => void) | null;
|
|
368
|
+
declare const NOOP: Function;
|
|
369
|
+
interface ActionProps<Props, Variables> {
|
|
370
|
+
send: Function;
|
|
371
|
+
data: Props & Variables;
|
|
372
|
+
onShow?: (props: ActionProps<Props, Variables>) => void | Promise<void>;
|
|
373
|
+
onChangeState?: (props: ActionProps<Props, Variables>) => void | Promise<void>;
|
|
374
|
+
}
|
|
326
375
|
/**
|
|
327
|
-
* An options for {@link
|
|
376
|
+
* An options for {@link create}
|
|
328
377
|
*/
|
|
329
|
-
interface
|
|
378
|
+
interface ActionOptions<Props, Variables> {
|
|
330
379
|
/**
|
|
331
|
-
* {@link Send} function to receive events triggered in
|
|
380
|
+
* {@link Send} function to receive events triggered in KARTE action.
|
|
332
381
|
*
|
|
333
382
|
* @default () => {}
|
|
334
383
|
*/
|
|
335
384
|
send?: Function;
|
|
336
385
|
/**
|
|
337
|
-
* {@link Props} used in
|
|
386
|
+
* {@link Props} used in KARTE action.
|
|
338
387
|
*
|
|
339
388
|
* @default {}
|
|
340
389
|
*/
|
|
341
390
|
props?: Props;
|
|
342
391
|
/**
|
|
343
|
-
* {@link Variables} in which user variables or action table used in
|
|
392
|
+
* {@link Variables} in which user variables or action table used in KARTE action.
|
|
344
393
|
*
|
|
345
394
|
* @default {}
|
|
346
395
|
*/
|
|
347
396
|
variables?: Variables;
|
|
397
|
+
/**
|
|
398
|
+
* {@link onShow} function to hook the phase of showing action in KARTE action.
|
|
399
|
+
*
|
|
400
|
+
* @default () => {}
|
|
401
|
+
*/
|
|
402
|
+
onShow?: (props: ActionProps<Props, Variables>) => void | Promise<void>;
|
|
403
|
+
/**
|
|
404
|
+
* {@link onClose} function to hook the phase of closing action in KARTE action.
|
|
405
|
+
*
|
|
406
|
+
* @default () => {}
|
|
407
|
+
*/
|
|
408
|
+
onClose?: (props: ActionProps<Props, Variables>) => void | Promise<void>;
|
|
409
|
+
/**
|
|
410
|
+
* {@link onClose} function to hook the phase of changing action state in KARTE action.
|
|
411
|
+
*
|
|
412
|
+
* @default () => {}
|
|
413
|
+
*/
|
|
414
|
+
onChangeState?: (props: ActionProps<Props, Variables>, newState: string) => void | Promise<void>;
|
|
348
415
|
}
|
|
349
416
|
// types of props to reference for internaly
|
|
350
417
|
interface _Props {
|
|
@@ -361,17 +428,74 @@ interface _Props {
|
|
|
361
428
|
show_on_time_count?: number;
|
|
362
429
|
}
|
|
363
430
|
/**
|
|
364
|
-
*
|
|
431
|
+
* Create the KARTE action
|
|
365
432
|
*
|
|
366
433
|
* @param App - An entry point of svelte component.
|
|
367
|
-
* @param options - A {@link
|
|
434
|
+
* @param options - A {@link ActionOptions | options}
|
|
368
435
|
*
|
|
369
|
-
* @return A function to
|
|
436
|
+
* @return A function to destroy KARTE action
|
|
370
437
|
*/
|
|
371
|
-
declare function
|
|
372
|
-
|
|
438
|
+
declare function create<Props extends _Props, Variables>(App: typeof SvelteComponentDev, options?: ActionOptions<Props, Variables>): () => void;
|
|
439
|
+
/**
|
|
440
|
+
* Dispatch the event to destroy KARTE action
|
|
441
|
+
*/
|
|
442
|
+
declare function dispatchDestroyEvent(): void;
|
|
443
|
+
/**
|
|
444
|
+
* Destory KARTE action
|
|
445
|
+
*/
|
|
446
|
+
declare function destroy(): void;
|
|
447
|
+
/**
|
|
448
|
+
* Show KARTE action
|
|
449
|
+
*/
|
|
450
|
+
declare function show(): void;
|
|
451
|
+
/**
|
|
452
|
+
* Close KARTE action
|
|
453
|
+
*/
|
|
454
|
+
declare function close(): void;
|
|
455
|
+
declare const KARTE_ACTION_ROOT = "karte-modal-root";
|
|
373
456
|
declare const KARTE_ACTION_RID = "karte-action-rid";
|
|
374
|
-
declare function
|
|
457
|
+
declare function ensureActionRoot(useShadow?: boolean): ShadowRoot | HTMLElement;
|
|
458
|
+
/**
|
|
459
|
+
* {@link onShow} function to set the function to hook the phase after showing action.
|
|
460
|
+
*
|
|
461
|
+
* @param {(props: ActionProps<Props, Variables>) => void | Promise<void>} fn Callback
|
|
462
|
+
*/
|
|
463
|
+
declare function onShow<Props extends _Props, Variables>(/**
|
|
464
|
+
* @param {ActionProps<Props, Variables>} props Properties of KARTE action
|
|
465
|
+
* @returns {void|Promise<void>}
|
|
466
|
+
*/
|
|
467
|
+
fn: (props: ActionProps<Props, Variables>) => void | Promise<void>): void;
|
|
468
|
+
/**
|
|
469
|
+
* {@link onClose} function to set the function to hook the phase before closing action.
|
|
470
|
+
*
|
|
471
|
+
* @param {(props: ActionProps<Props, Variables>) => void | Promise<void>} fn Callback
|
|
472
|
+
*/
|
|
473
|
+
declare function onClose<Props extends _Props, Variables>(/**
|
|
474
|
+
* @param {ActionProps<Props, Variables>} props Properties of KARTE action
|
|
475
|
+
* @returns {void|Promise<void>}
|
|
476
|
+
*/
|
|
477
|
+
fn: (props: ActionProps<Props, Variables>) => void | Promise<void>): void;
|
|
478
|
+
/**
|
|
479
|
+
* {@link onDestory} function to set the function to hook the phase before destroying action.
|
|
480
|
+
*
|
|
481
|
+
* @param {(props: ActionProps<Props, Variables>) => void | Promise<void>} fn Callback
|
|
482
|
+
*/
|
|
483
|
+
declare function onDestroy<Props extends _Props, Variables>(/**
|
|
484
|
+
* @param {ActionProps<Props, Variables>} props Properties of KARTE action
|
|
485
|
+
* @returns {void|Promise<void>}
|
|
486
|
+
*/
|
|
487
|
+
fn: (props: ActionProps<Props, Variables>) => void | Promise<void>): void;
|
|
488
|
+
/**
|
|
489
|
+
* {@link onChangeState} function to set the function to hook the phase after changing action state.
|
|
490
|
+
*
|
|
491
|
+
* @param {(props: ActionProps, newState: string) => void | Promise<void>} fn Callback
|
|
492
|
+
*/
|
|
493
|
+
declare function onChangeState<Props extends _Props, Variables>(/**
|
|
494
|
+
* @param {ActionProps<Props, Variables>} props Properties of KARTE action
|
|
495
|
+
* @param {string} newState New state of KARTE action
|
|
496
|
+
* @returns {void|Promise<void>}
|
|
497
|
+
*/
|
|
498
|
+
fn: (props: ActionProps<Props, Variables>, newState: string) => void | Promise<void>): void;
|
|
375
499
|
declare const h: (type: string, props: any, ...children: Array<any>) => HTMLElement;
|
|
376
500
|
declare function createFog({ color, opacity, zIndex, onclick }: {
|
|
377
501
|
color?: string;
|
|
@@ -384,11 +508,28 @@ declare function createFog({ color, opacity, zIndex, onclick }: {
|
|
|
384
508
|
};
|
|
385
509
|
type EmbedLogic = "replace" | "append" | "prepend" | "after" | "before";
|
|
386
510
|
declare function embed(target: HTMLElement, replace: HTMLElement, embed_method: EmbedLogic): void;
|
|
511
|
+
/**
|
|
512
|
+
* {@link applyCss} apply CSS to KARTE action.
|
|
513
|
+
*
|
|
514
|
+
* @param {string} css CSS
|
|
515
|
+
*/
|
|
516
|
+
declare function applyCss(css: string): Promise<any>;
|
|
517
|
+
/**
|
|
518
|
+
* {@link loadStyle} load global style to KARTE action.
|
|
519
|
+
*
|
|
520
|
+
* @param {string} href Link of style file
|
|
521
|
+
*/
|
|
522
|
+
declare function loadStyle(href: string): Promise<any>;
|
|
523
|
+
// -------- The following codes are deprecated --------
|
|
524
|
+
declare const showModal: typeof create; // @deprecated
|
|
525
|
+
type ModalOptions<Props, Variables> = ActionOptions<Props, Variables>; // @deprecated
|
|
526
|
+
declare const KARTE_MODAL_ROOT = "karte-modal-root"; // @deprecated
|
|
527
|
+
declare const ensureModalRoot: typeof ensureActionRoot; // @deprecated
|
|
387
528
|
/**
|
|
388
529
|
* An options for {@link createApp}
|
|
389
530
|
* @deprecated
|
|
390
531
|
*/
|
|
391
|
-
type AppOptions<Props, Variables> =
|
|
532
|
+
type AppOptions<Props, Variables> = ActionOptions<Props, Variables>;
|
|
392
533
|
/**
|
|
393
534
|
* App application instance that is with {@link createApp}
|
|
394
535
|
* @deprecated
|
|
@@ -428,7 +569,7 @@ declare const collection: (config: {
|
|
|
428
569
|
} | null | undefined, cb: (err: Error | null, items?: any) => void): void;
|
|
429
570
|
set(key: string, value: string, cb: (err: Error | null) => void): void;
|
|
430
571
|
};
|
|
431
|
-
export { Store, getStoreState, ActionEventHandler, CONSTANTS, actionId, state, closed, maximumZindex, customHandlers, initialize, finalize, send_event, isPreview, setMiximumZindex, none, moveTo, linkTo, closeApp, runScript, execOnClickOperation, haveFunction, customAnimation, handleFocus, setPreviousFocus, handleKeydown, getPositionStyle, getTransform, getMarginStyle, onScroll, onTime, hasSuffix, toBr, randStr, PropTypes, PropType, Code, MediaQueries, MediaQuery, Directions, Direction, AnimationStyles, AnimationStyle, ModalPositions, ModalPosition, ModalMargin, ModalPlacement, DefaultModalPlacement, OperationArgumentType, Operation, OnClickOperationOptions, OnClickOperation, LongText, Url, Image, LengthUnits, LengthUnit, Length, Color, Justifies, Justify, Alignments, Alignment, ObjectFits, ObjectFit, Repeats, Repeat, BackgroundSizes, BackgroundSize, Cursors, Cursor, Overflows, Overflow, Style, StateName, hideOnScroll, hideOnTime, showOnScroll, showOnTime,
|
|
572
|
+
export { Store, getStoreState, ActionEventHandler, CONSTANTS, actionId, ACTION_SHOW_EVENT, ACTION_CLOSE_EVENT, ACTION_DESTROY_EVENT, state, states, closed, maximumZindex, internalHandlers, customHandlers, destroyed, stopped, customVariables, setAutoStart, setState, initialize, finalize, send_event, isPreview, setMiximumZindex, none, moveTo, linkTo, closeApp, runScript, execOnClickOperation, haveFunction, customAnimation, loadGlobalScript, applyGlobalCss, loadGlobalStyle, handleFocus, setPreviousFocus, handleKeydown, getPositionStyle, getTransform, getMarginStyle, onScroll, onTime, hasSuffix, toBr, randStr, PropTypes, PropType, Code, MediaQueries, MediaQuery, Directions, Direction, AnimationStyles, AnimationStyle, ModalPositions, ModalPosition, ModalMargin, ModalPlacement, DefaultModalPlacement, OperationArgumentType, Operation, OnClickOperationOptions, OnClickOperation, LongText, Url, Image, LengthUnits, LengthUnit, Length, Color, Justifies, Justify, Alignments, Alignment, ObjectFits, ObjectFit, Repeats, Repeat, BackgroundSizes, BackgroundSize, Cursors, Cursor, Overflows, Overflow, Style, StateName, hideOnScroll, hideOnTime, showOnScroll, showOnTime, NOOP, ActionProps, ActionOptions, create, dispatchDestroyEvent, destroy, show, close, KARTE_ACTION_ROOT, KARTE_ACTION_RID, ensureActionRoot, onShow, onClose, onDestroy, onChangeState, h, createFog, EmbedLogic, embed, applyCss, loadStyle, showModal, ModalOptions, KARTE_MODAL_ROOT, ensureModalRoot, AppOptions, App, createApp, collection };
|
|
432
573
|
export { default as State } from './components/State.svelte';
|
|
433
574
|
export { default as StateItem } from './components/StateItem.svelte';
|
|
434
575
|
export { default as Modal } from './components/Modal.svelte';
|
package/dist/index.es.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { writable, get } from 'svelte/store';
|
|
2
2
|
import { linear, elasticOut, cubicOut } from 'svelte/easing';
|
|
3
3
|
import { SvelteComponent, init, safe_not_equal, append_styles, create_slot, create_component, space, mount_component, insert, update_slot_base, get_all_dirty_from_scope, get_slot_changes, transition_in, transition_out, destroy_component, detach, empty, group_outros, check_outros, component_subscribe, noop, element, attr, listen, is_function, append, add_render_callback, create_in_transition, svg_element, binding_callbacks, destroy_each, text, set_data, src_url_equal, null_to_empty } from 'svelte/internal';
|
|
4
|
-
import { createEventDispatcher, onMount, onDestroy, setContext, getContext } from 'svelte';
|
|
4
|
+
import { createEventDispatcher, onMount, onDestroy as onDestroy$1, setContext, getContext } from 'svelte';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* 内部的に使われている、UIから選択できない関数
|
|
@@ -139,21 +139,41 @@ const CONSTANTS = {
|
|
|
139
139
|
};
|
|
140
140
|
const functionOptions = writable({});
|
|
141
141
|
const actionId = randStr();
|
|
142
|
-
|
|
142
|
+
const ACTION_SHOW_EVENT = `KARTE-ACTION-SHOW-${actionId}`;
|
|
143
|
+
const ACTION_CLOSE_EVENT = `KARTE-ACTION-CLOSE-${actionId}`;
|
|
144
|
+
const ACTION_DESTROY_EVENT = `KARTE-ACTION-DESTROY-${actionId}`;
|
|
145
|
+
// Store to handle current state ID
|
|
143
146
|
const state = writable('/');
|
|
144
|
-
//
|
|
147
|
+
// Store to handle all state IDs
|
|
148
|
+
const states = writable([]);
|
|
149
|
+
// Store to handle visibility of action
|
|
145
150
|
const closed = writable(false);
|
|
146
|
-
//
|
|
151
|
+
// Store to handle max z-index for grid items
|
|
147
152
|
const maximumZindex = writable(0);
|
|
148
|
-
//
|
|
153
|
+
// Store to handle internal event handlers
|
|
154
|
+
const internalHandlers = writable({});
|
|
155
|
+
// Store to handle custom event handlers
|
|
149
156
|
const customHandlers = writable({});
|
|
157
|
+
// Store to handle destruction of action
|
|
158
|
+
const destroyed = writable(false);
|
|
159
|
+
// Store to handle stop of action
|
|
160
|
+
const stopped = writable(false);
|
|
161
|
+
// Store to handle custom variables
|
|
162
|
+
const customVariables = writable({});
|
|
163
|
+
/**
|
|
164
|
+
* {@link setAutoStart} function to set auto start flag.
|
|
165
|
+
*
|
|
166
|
+
* @param {boolean} on
|
|
167
|
+
*/
|
|
168
|
+
const setAutoStart = (on = true) => {
|
|
169
|
+
stopped.set(!on);
|
|
170
|
+
};
|
|
150
171
|
const setState = (event) => {
|
|
151
172
|
if (event.detail.actionId === actionId || event.detail.actionId === CONSTANTS.ALL_ACTION_ID) {
|
|
152
173
|
state.set(event.detail.to);
|
|
153
174
|
}
|
|
154
175
|
};
|
|
155
176
|
const initialize = (options) => {
|
|
156
|
-
window.addEventListener(CONSTANTS.STATE_EVENT, setState);
|
|
157
177
|
if (options?.initialState) {
|
|
158
178
|
state.set(options?.initialState);
|
|
159
179
|
}
|
|
@@ -162,7 +182,6 @@ const initialize = (options) => {
|
|
|
162
182
|
return () => finalize();
|
|
163
183
|
};
|
|
164
184
|
const finalize = () => {
|
|
165
|
-
window.removeEventListener(CONSTANTS.STATE_EVENT, setState);
|
|
166
185
|
functionOptions.set({});
|
|
167
186
|
};
|
|
168
187
|
const send_event = (event_name, values) => {
|
|
@@ -288,6 +307,49 @@ function customAnimation(node, { transform, animationStyle, delay = 0, duration
|
|
|
288
307
|
css: (progress) => getAnimation({ type: animationStyle, x, y, progress }),
|
|
289
308
|
};
|
|
290
309
|
}
|
|
310
|
+
/**
|
|
311
|
+
* {@link loadGlobalScript} load JavaScript that does not support ESM.
|
|
312
|
+
*
|
|
313
|
+
* @param {string} src Link of JavaScript file
|
|
314
|
+
*/
|
|
315
|
+
async function loadGlobalScript(src) {
|
|
316
|
+
return new Promise((resolve, reject) => {
|
|
317
|
+
const script = document.createElement('script');
|
|
318
|
+
script.src = src;
|
|
319
|
+
document.body.appendChild(script);
|
|
320
|
+
script.addEventListener('load', () => resolve(script));
|
|
321
|
+
script.addEventListener('error', () => reject(script));
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* {@link applyGlobalCss} apply global CSS to WEB page.
|
|
326
|
+
*
|
|
327
|
+
* @param {string} css CSS
|
|
328
|
+
*/
|
|
329
|
+
async function applyGlobalCss(css) {
|
|
330
|
+
return new Promise((resolve, reject) => {
|
|
331
|
+
const style = document.createElement('style');
|
|
332
|
+
style.textContent = css;
|
|
333
|
+
document.body.appendChild(style);
|
|
334
|
+
style.addEventListener('load', () => resolve(style));
|
|
335
|
+
style.addEventListener('error', () => reject(style));
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* {@link loadGlobalStyle} load global style to WEB page.
|
|
340
|
+
*
|
|
341
|
+
* @param {string} href Link of style file
|
|
342
|
+
*/
|
|
343
|
+
async function loadGlobalStyle(href) {
|
|
344
|
+
return new Promise((resolve, reject) => {
|
|
345
|
+
const link = document.createElement('link');
|
|
346
|
+
link.rel = 'stylesheet';
|
|
347
|
+
link.href = href;
|
|
348
|
+
document.body.appendChild(link);
|
|
349
|
+
link.addEventListener('load', () => resolve(link));
|
|
350
|
+
link.addEventListener('error', () => reject(link));
|
|
351
|
+
});
|
|
352
|
+
}
|
|
291
353
|
|
|
292
354
|
const PropTypes = [
|
|
293
355
|
'BooleanKeyword',
|
|
@@ -478,69 +540,129 @@ function checkAndDo(checkFn, fn, ...conditionFns) {
|
|
|
478
540
|
return haveCondition ? cleanupAll : null;
|
|
479
541
|
}
|
|
480
542
|
|
|
481
|
-
const NOOP = () => { };
|
|
543
|
+
const NOOP = (_args) => { };
|
|
482
544
|
/**
|
|
483
|
-
*
|
|
545
|
+
* Create the KARTE action
|
|
484
546
|
*
|
|
485
547
|
* @param App - An entry point of svelte component.
|
|
486
|
-
* @param options - A {@link
|
|
548
|
+
* @param options - A {@link ActionOptions | options}
|
|
487
549
|
*
|
|
488
|
-
* @return A function to
|
|
550
|
+
* @return A function to destroy KARTE action
|
|
489
551
|
*/
|
|
490
|
-
function
|
|
552
|
+
function create(App, options = {
|
|
491
553
|
send: () => { },
|
|
492
554
|
props: {},
|
|
493
555
|
variables: {},
|
|
494
556
|
}) {
|
|
495
557
|
let app = null;
|
|
558
|
+
const data = { ...options.props, ...options.variables };
|
|
496
559
|
const close = () => {
|
|
497
|
-
if (app) {
|
|
498
|
-
|
|
499
|
-
|
|
560
|
+
if (!app) {
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
closed.set(true);
|
|
564
|
+
window.removeEventListener(CONSTANTS.STATE_EVENT, setState);
|
|
565
|
+
if (options.onClose) {
|
|
566
|
+
options.onClose({ send: options.send, data });
|
|
500
567
|
}
|
|
568
|
+
app.$destroy();
|
|
569
|
+
app = null;
|
|
501
570
|
};
|
|
571
|
+
window.addEventListener(ACTION_CLOSE_EVENT, close);
|
|
502
572
|
const show = () => {
|
|
503
573
|
if (app) {
|
|
504
574
|
return;
|
|
505
575
|
}
|
|
506
576
|
options.send('message_open');
|
|
577
|
+
closed.set(false);
|
|
578
|
+
window.addEventListener(CONSTANTS.STATE_EVENT, setState);
|
|
507
579
|
app = new App({
|
|
508
580
|
target: ensureModalRoot(!false),
|
|
509
581
|
hydrate: false,
|
|
510
582
|
props: {
|
|
511
583
|
send: options.send,
|
|
512
584
|
close,
|
|
513
|
-
data
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
},
|
|
585
|
+
data,
|
|
586
|
+
onShow: options.onShow,
|
|
587
|
+
onChangeState: options.onChangeState,
|
|
517
588
|
},
|
|
518
589
|
});
|
|
519
590
|
};
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
const
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
591
|
+
window.addEventListener(ACTION_SHOW_EVENT, show);
|
|
592
|
+
const currying = (conditionFn, options) => (fn) => conditionFn(options.props, fn);
|
|
593
|
+
const startClose = () => {
|
|
594
|
+
let cleanup;
|
|
595
|
+
// if in hydrate mode (preview), nothing is done, since action will be disposed and closed in the preview module
|
|
596
|
+
if (options.props.hide_and_condition) {
|
|
597
|
+
cleanup = and(close, currying(hideOnScroll, options), currying(hideOnTime, options)) || NOOP;
|
|
598
|
+
}
|
|
599
|
+
else {
|
|
600
|
+
cleanup = or(close, currying(hideOnScroll, options), currying(hideOnTime, options)) || NOOP;
|
|
601
|
+
}
|
|
602
|
+
return cleanup;
|
|
603
|
+
};
|
|
526
604
|
const _show = () => {
|
|
527
605
|
show();
|
|
528
606
|
return close;
|
|
529
607
|
};
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
608
|
+
const startShow = () => {
|
|
609
|
+
let cleanup;
|
|
610
|
+
// if in hydrate mode (preview), always show action
|
|
611
|
+
if (options.props.show_and_condition) {
|
|
612
|
+
cleanup =
|
|
613
|
+
and(show, currying(showOnScroll, options), currying(showOnTime, options)) || _show();
|
|
614
|
+
}
|
|
615
|
+
else {
|
|
616
|
+
cleanup = or(show, currying(showOnScroll, options), currying(showOnTime, options)) || _show();
|
|
617
|
+
}
|
|
618
|
+
return cleanup;
|
|
619
|
+
};
|
|
620
|
+
// init
|
|
621
|
+
let hideCleanup = NOOP;
|
|
622
|
+
let showCleanup = NOOP;
|
|
623
|
+
if (!getStoreState(stopped)) {
|
|
624
|
+
hideCleanup = startShow();
|
|
625
|
+
showCleanup = startClose();
|
|
626
|
+
}
|
|
535
627
|
return () => {
|
|
536
628
|
close();
|
|
537
|
-
showCleanup();
|
|
538
629
|
hideCleanup();
|
|
630
|
+
showCleanup();
|
|
631
|
+
window.removeEventListener(ACTION_SHOW_EVENT, show);
|
|
632
|
+
window.removeEventListener(ACTION_CLOSE_EVENT, close);
|
|
539
633
|
};
|
|
540
634
|
}
|
|
541
|
-
|
|
635
|
+
/**
|
|
636
|
+
* Dispatch the event to destroy KARTE action
|
|
637
|
+
*/
|
|
638
|
+
function dispatchDestroyEvent() {
|
|
639
|
+
const event = new Event(ACTION_DESTROY_EVENT);
|
|
640
|
+
window.dispatchEvent(event);
|
|
641
|
+
}
|
|
642
|
+
/**
|
|
643
|
+
* Destory KARTE action
|
|
644
|
+
*/
|
|
645
|
+
function destroy() {
|
|
646
|
+
destroyed.set(true);
|
|
647
|
+
dispatchDestroyEvent();
|
|
648
|
+
}
|
|
649
|
+
/**
|
|
650
|
+
* Show KARTE action
|
|
651
|
+
*/
|
|
652
|
+
function show() {
|
|
653
|
+
const event = new Event(ACTION_SHOW_EVENT);
|
|
654
|
+
window.dispatchEvent(event);
|
|
655
|
+
}
|
|
656
|
+
/**
|
|
657
|
+
* Close KARTE action
|
|
658
|
+
*/
|
|
659
|
+
function close() {
|
|
660
|
+
const event = new Event(ACTION_CLOSE_EVENT);
|
|
661
|
+
window.dispatchEvent(event);
|
|
662
|
+
}
|
|
663
|
+
const KARTE_ACTION_ROOT = 'karte-modal-root';
|
|
542
664
|
const KARTE_ACTION_RID = 'karte-action-rid';
|
|
543
|
-
function
|
|
665
|
+
function ensureActionRoot(useShadow = true) {
|
|
544
666
|
let el = document.querySelector(`.${KARTE_MODAL_ROOT}[data-${KARTE_ACTION_RID}='${actionId}']`);
|
|
545
667
|
if (el == null) {
|
|
546
668
|
el = h('div', { class: KARTE_MODAL_ROOT, [`data-${KARTE_ACTION_RID}`]: actionId });
|
|
@@ -554,6 +676,71 @@ function ensureModalRoot(useShadow = true) {
|
|
|
554
676
|
return el;
|
|
555
677
|
}
|
|
556
678
|
}
|
|
679
|
+
/**
|
|
680
|
+
* {@link onShow} function to set the function to hook the phase after showing action.
|
|
681
|
+
*
|
|
682
|
+
* @param {(props: ActionProps<Props, Variables>) => void | Promise<void>} fn Callback
|
|
683
|
+
*/
|
|
684
|
+
function onShow(
|
|
685
|
+
/**
|
|
686
|
+
* @param {ActionProps<Props, Variables>} props Properties of KARTE action
|
|
687
|
+
* @returns {void|Promise<void>}
|
|
688
|
+
*/
|
|
689
|
+
fn) {
|
|
690
|
+
internalHandlers.update(current => {
|
|
691
|
+
current.onShow = fn;
|
|
692
|
+
return current;
|
|
693
|
+
});
|
|
694
|
+
}
|
|
695
|
+
/**
|
|
696
|
+
* {@link onClose} function to set the function to hook the phase before closing action.
|
|
697
|
+
*
|
|
698
|
+
* @param {(props: ActionProps<Props, Variables>) => void | Promise<void>} fn Callback
|
|
699
|
+
*/
|
|
700
|
+
function onClose(
|
|
701
|
+
/**
|
|
702
|
+
* @param {ActionProps<Props, Variables>} props Properties of KARTE action
|
|
703
|
+
* @returns {void|Promise<void>}
|
|
704
|
+
*/
|
|
705
|
+
fn) {
|
|
706
|
+
internalHandlers.update(current => {
|
|
707
|
+
current.onClose = fn;
|
|
708
|
+
return current;
|
|
709
|
+
});
|
|
710
|
+
}
|
|
711
|
+
/**
|
|
712
|
+
* {@link onDestory} function to set the function to hook the phase before destroying action.
|
|
713
|
+
*
|
|
714
|
+
* @param {(props: ActionProps<Props, Variables>) => void | Promise<void>} fn Callback
|
|
715
|
+
*/
|
|
716
|
+
function onDestroy(
|
|
717
|
+
/**
|
|
718
|
+
* @param {ActionProps<Props, Variables>} props Properties of KARTE action
|
|
719
|
+
* @returns {void|Promise<void>}
|
|
720
|
+
*/
|
|
721
|
+
fn) {
|
|
722
|
+
internalHandlers.update(current => {
|
|
723
|
+
current.onDestroy = fn;
|
|
724
|
+
return current;
|
|
725
|
+
});
|
|
726
|
+
}
|
|
727
|
+
/**
|
|
728
|
+
* {@link onChangeState} function to set the function to hook the phase after changing action state.
|
|
729
|
+
*
|
|
730
|
+
* @param {(props: ActionProps, newState: string) => void | Promise<void>} fn Callback
|
|
731
|
+
*/
|
|
732
|
+
function onChangeState(
|
|
733
|
+
/**
|
|
734
|
+
* @param {ActionProps<Props, Variables>} props Properties of KARTE action
|
|
735
|
+
* @param {string} newState New state of KARTE action
|
|
736
|
+
* @returns {void|Promise<void>}
|
|
737
|
+
*/
|
|
738
|
+
fn) {
|
|
739
|
+
internalHandlers.update(current => {
|
|
740
|
+
current.onChangeState = fn;
|
|
741
|
+
return current;
|
|
742
|
+
});
|
|
743
|
+
}
|
|
557
744
|
const h = (type, props, ...children) => {
|
|
558
745
|
const el = document.createElement(type);
|
|
559
746
|
for (const key of Object.keys(props)) {
|
|
@@ -614,6 +801,52 @@ function embed(target, replace, embed_method) {
|
|
|
614
801
|
target.before(replace);
|
|
615
802
|
}
|
|
616
803
|
}
|
|
804
|
+
function getActionShadowRoot() {
|
|
805
|
+
const root = document.querySelector(`.${KARTE_ACTION_ROOT}[data-${KARTE_ACTION_RID}='${actionId}']`);
|
|
806
|
+
if (!root || !root.shadowRoot) {
|
|
807
|
+
return null;
|
|
808
|
+
}
|
|
809
|
+
return root.shadowRoot;
|
|
810
|
+
}
|
|
811
|
+
/**
|
|
812
|
+
* {@link applyCss} apply CSS to KARTE action.
|
|
813
|
+
*
|
|
814
|
+
* @param {string} css CSS
|
|
815
|
+
*/
|
|
816
|
+
async function applyCss(css) {
|
|
817
|
+
return new Promise((resolve, reject) => {
|
|
818
|
+
const style = document.createElement('style');
|
|
819
|
+
style.textContent = css;
|
|
820
|
+
const shadowRoot = getActionShadowRoot();
|
|
821
|
+
if (!shadowRoot)
|
|
822
|
+
return;
|
|
823
|
+
shadowRoot.append(style);
|
|
824
|
+
style.addEventListener('load', () => resolve(style));
|
|
825
|
+
style.addEventListener('error', () => reject(style));
|
|
826
|
+
});
|
|
827
|
+
}
|
|
828
|
+
/**
|
|
829
|
+
* {@link loadStyle} load global style to KARTE action.
|
|
830
|
+
*
|
|
831
|
+
* @param {string} href Link of style file
|
|
832
|
+
*/
|
|
833
|
+
async function loadStyle(href) {
|
|
834
|
+
return new Promise((resolve, reject) => {
|
|
835
|
+
const link = document.createElement('link');
|
|
836
|
+
link.rel = 'stylesheet';
|
|
837
|
+
link.href = href;
|
|
838
|
+
const shadowRoot = getActionShadowRoot();
|
|
839
|
+
if (!shadowRoot)
|
|
840
|
+
return;
|
|
841
|
+
shadowRoot.append(link);
|
|
842
|
+
link.addEventListener('load', () => resolve(link));
|
|
843
|
+
link.addEventListener('error', () => reject(link));
|
|
844
|
+
});
|
|
845
|
+
}
|
|
846
|
+
// -------- The following codes are deprecated --------
|
|
847
|
+
const showModal = create; // @deprecated
|
|
848
|
+
const KARTE_MODAL_ROOT = KARTE_ACTION_ROOT; // @deprecated
|
|
849
|
+
const ensureModalRoot = ensureActionRoot; // @deprecated
|
|
617
850
|
/**
|
|
618
851
|
* Create an application instance
|
|
619
852
|
* @deprecated
|
|
@@ -931,6 +1164,17 @@ function instance$e($$self, $$props, $$invalidate) {
|
|
|
931
1164
|
if ('$$scope' in $$props) $$invalidate(2, $$scope = $$props.$$scope);
|
|
932
1165
|
};
|
|
933
1166
|
|
|
1167
|
+
$$self.$$.update = () => {
|
|
1168
|
+
if ($$self.$$.dirty & /*path*/ 1) {
|
|
1169
|
+
{
|
|
1170
|
+
states.update(current => {
|
|
1171
|
+
current.push(path);
|
|
1172
|
+
return current;
|
|
1173
|
+
});
|
|
1174
|
+
}
|
|
1175
|
+
}
|
|
1176
|
+
};
|
|
1177
|
+
|
|
934
1178
|
return [path, $state, $$scope, slots];
|
|
935
1179
|
}
|
|
936
1180
|
|
|
@@ -1331,7 +1575,7 @@ function instance$c($$self, $$props, $$invalidate) {
|
|
|
1331
1575
|
$$invalidate(6, visible = true);
|
|
1332
1576
|
});
|
|
1333
1577
|
|
|
1334
|
-
onDestroy(() => setPreviousFocus());
|
|
1578
|
+
onDestroy$1(() => setPreviousFocus());
|
|
1335
1579
|
|
|
1336
1580
|
function div_binding($$value) {
|
|
1337
1581
|
binding_callbacks[$$value ? 'unshift' : 'push'](() => {
|
|
@@ -3089,4 +3333,4 @@ class ImageBlock extends SvelteComponent {
|
|
|
3089
3333
|
}
|
|
3090
3334
|
}
|
|
3091
3335
|
|
|
3092
|
-
export { Alignments, AnimationStyles, BackgroundSizes, CONSTANTS, Cursors, DefaultModalPlacement, Directions, Flex, FlexItem, Grid, GridItem, GridModalState, ImageBlock, ImageElement, Justifies, KARTE_ACTION_RID, KARTE_MODAL_ROOT, LengthUnits, MediaQueries, Modal, ModalPositions, ObjectFits, OnClickOperationOptions, Overflows, PropTypes, Repeats, State, StateItem, TextBlock, TextButtonBlock, TextButtonElement, TextElement, actionId, closeApp, closed, collection, createApp, createFog, customAnimation, customHandlers, embed, ensureModalRoot, execOnClickOperation, finalize, getMarginStyle, getPositionStyle, getStoreState, getTransform, h, handleFocus, handleKeydown, hasSuffix, haveFunction, hideOnScroll, hideOnTime, initialize, isPreview, linkTo, maximumZindex, moveTo, none, onScroll, onTime, randStr, runScript, send_event, setMiximumZindex, setPreviousFocus, showModal, showOnScroll, showOnTime, state, toBr };
|
|
3336
|
+
export { ACTION_CLOSE_EVENT, ACTION_DESTROY_EVENT, ACTION_SHOW_EVENT, Alignments, AnimationStyles, BackgroundSizes, CONSTANTS, Cursors, DefaultModalPlacement, Directions, Flex, FlexItem, Grid, GridItem, GridModalState, ImageBlock, ImageElement, Justifies, KARTE_ACTION_RID, KARTE_ACTION_ROOT, KARTE_MODAL_ROOT, LengthUnits, MediaQueries, Modal, ModalPositions, NOOP, ObjectFits, OnClickOperationOptions, Overflows, PropTypes, Repeats, State, StateItem, TextBlock, TextButtonBlock, TextButtonElement, TextElement, actionId, applyCss, applyGlobalCss, close, closeApp, closed, collection, create, createApp, createFog, customAnimation, customHandlers, customVariables, destroy, destroyed, dispatchDestroyEvent, embed, ensureActionRoot, ensureModalRoot, execOnClickOperation, finalize, getMarginStyle, getPositionStyle, getStoreState, getTransform, h, handleFocus, handleKeydown, hasSuffix, haveFunction, hideOnScroll, hideOnTime, initialize, internalHandlers, isPreview, linkTo, loadGlobalScript, loadGlobalStyle, loadStyle, maximumZindex, moveTo, none, onChangeState, onClose, onDestroy, onScroll, onShow, onTime, randStr, runScript, send_event, setAutoStart, setMiximumZindex, setPreviousFocus, setState, show, showModal, showOnScroll, showOnTime, state, states, stopped, toBr };
|