@elementor/editor-v1-adapters 0.12.1 → 3.32.0-20
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/index.d.mts +10 -2
- package/dist/index.d.ts +10 -2
- package/dist/index.js +16 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +15 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/index.ts +1 -1
- package/src/readers/index.ts +7 -1
- package/src/undoable/undoable.ts +12 -4
package/dist/index.d.mts
CHANGED
|
@@ -79,8 +79,13 @@ declare function useRouteStatus(route: RouteEventDescriptor['name'], { blockOnKi
|
|
|
79
79
|
isBlocked: boolean;
|
|
80
80
|
};
|
|
81
81
|
|
|
82
|
+
declare const EXPERIMENTAL_FEATURES: {
|
|
83
|
+
CUSTOM_CSS: string;
|
|
84
|
+
TRANSITIONS: string;
|
|
85
|
+
UNSTABLE_REPEATER: string;
|
|
86
|
+
};
|
|
82
87
|
declare function isRouteActive(route: string): boolean;
|
|
83
|
-
declare const isExperimentActive: (experiment: string) => boolean;
|
|
88
|
+
declare const isExperimentActive: (experiment: keyof typeof EXPERIMENTAL_FEATURES | string) => boolean;
|
|
84
89
|
|
|
85
90
|
type Payload = Record<string, any> | undefined;
|
|
86
91
|
type LabelGenerator<TPayload extends Payload, TDoReturn> = (payload: TPayload, doReturn: TDoReturn) => string;
|
|
@@ -92,6 +97,9 @@ type Actions<TPayload extends Payload, TDoReturn, TUndoReturn> = {
|
|
|
92
97
|
type Options<TPayload extends Payload, TDoReturn> = {
|
|
93
98
|
title: string | LabelGenerator<TPayload, TDoReturn>;
|
|
94
99
|
subtitle?: string | LabelGenerator<TPayload, TDoReturn>;
|
|
100
|
+
debounce?: {
|
|
101
|
+
wait: number;
|
|
102
|
+
};
|
|
95
103
|
};
|
|
96
104
|
declare function undoable<TDoReturn, TUndoReturn>(actions: Actions<undefined, TDoReturn, TUndoReturn>, options: Options<undefined, NoInfer<TDoReturn>>): () => TDoReturn;
|
|
97
105
|
declare function undoable<TPayload extends NonNullable<Payload>, TDoReturn, TUndoReturn>(actions: Actions<TPayload, TDoReturn, TUndoReturn>, options: Options<TPayload, NoInfer<TDoReturn>>): (payload: TPayload) => TDoReturn;
|
|
@@ -131,4 +139,4 @@ type BlockCommandArgs = {
|
|
|
131
139
|
};
|
|
132
140
|
declare function blockCommand({ command, condition }: BlockCommandArgs): DataHook;
|
|
133
141
|
|
|
134
|
-
export { type CommandEvent, type CommandEventDescriptor, type EditMode, type EventDescriptor, type ExtendedWindow, type HistoryItem, type ListenerCallback, type ListenerEvent, type RouteEvent, type RouteEventDescriptor, type UseRouteStatusOptions, type WindowEvent, type WindowEventDescriptor, type WindowWithHistoryManager, dispatchReadyEvent as __privateDispatchReadyEvent, flushListeners as __privateFlushListeners, isRouteActive as __privateIsRouteActive, listenTo as __privateListenTo, openRoute as __privateOpenRoute, registerRoute as __privateRegisterRoute, runCommand as __privateRunCommand, runCommandSync as __privateRunCommandSync, setReady as __privateSetReady, useIsRouteActive as __privateUseIsRouteActive, useListenTo as __privateUseListenTo, useRouteStatus as __privateUseRouteStatus, blockCommand, changeEditMode, commandEndEvent, commandStartEvent, dispatchReadyEvent, flushListeners, isExperimentActive, isReady, listenTo, registerDataHook, routeCloseEvent, routeOpenEvent, setReady, undoable, useEditMode, v1ReadyEvent, windowEvent };
|
|
142
|
+
export { type CommandEvent, type CommandEventDescriptor, EXPERIMENTAL_FEATURES, type EditMode, type EventDescriptor, type ExtendedWindow, type HistoryItem, type ListenerCallback, type ListenerEvent, type RouteEvent, type RouteEventDescriptor, type UseRouteStatusOptions, type WindowEvent, type WindowEventDescriptor, type WindowWithHistoryManager, dispatchReadyEvent as __privateDispatchReadyEvent, flushListeners as __privateFlushListeners, isRouteActive as __privateIsRouteActive, listenTo as __privateListenTo, openRoute as __privateOpenRoute, registerRoute as __privateRegisterRoute, runCommand as __privateRunCommand, runCommandSync as __privateRunCommandSync, setReady as __privateSetReady, useIsRouteActive as __privateUseIsRouteActive, useListenTo as __privateUseListenTo, useRouteStatus as __privateUseRouteStatus, blockCommand, changeEditMode, commandEndEvent, commandStartEvent, dispatchReadyEvent, flushListeners, isExperimentActive, isReady, listenTo, registerDataHook, routeCloseEvent, routeOpenEvent, setReady, undoable, useEditMode, v1ReadyEvent, windowEvent };
|
package/dist/index.d.ts
CHANGED
|
@@ -79,8 +79,13 @@ declare function useRouteStatus(route: RouteEventDescriptor['name'], { blockOnKi
|
|
|
79
79
|
isBlocked: boolean;
|
|
80
80
|
};
|
|
81
81
|
|
|
82
|
+
declare const EXPERIMENTAL_FEATURES: {
|
|
83
|
+
CUSTOM_CSS: string;
|
|
84
|
+
TRANSITIONS: string;
|
|
85
|
+
UNSTABLE_REPEATER: string;
|
|
86
|
+
};
|
|
82
87
|
declare function isRouteActive(route: string): boolean;
|
|
83
|
-
declare const isExperimentActive: (experiment: string) => boolean;
|
|
88
|
+
declare const isExperimentActive: (experiment: keyof typeof EXPERIMENTAL_FEATURES | string) => boolean;
|
|
84
89
|
|
|
85
90
|
type Payload = Record<string, any> | undefined;
|
|
86
91
|
type LabelGenerator<TPayload extends Payload, TDoReturn> = (payload: TPayload, doReturn: TDoReturn) => string;
|
|
@@ -92,6 +97,9 @@ type Actions<TPayload extends Payload, TDoReturn, TUndoReturn> = {
|
|
|
92
97
|
type Options<TPayload extends Payload, TDoReturn> = {
|
|
93
98
|
title: string | LabelGenerator<TPayload, TDoReturn>;
|
|
94
99
|
subtitle?: string | LabelGenerator<TPayload, TDoReturn>;
|
|
100
|
+
debounce?: {
|
|
101
|
+
wait: number;
|
|
102
|
+
};
|
|
95
103
|
};
|
|
96
104
|
declare function undoable<TDoReturn, TUndoReturn>(actions: Actions<undefined, TDoReturn, TUndoReturn>, options: Options<undefined, NoInfer<TDoReturn>>): () => TDoReturn;
|
|
97
105
|
declare function undoable<TPayload extends NonNullable<Payload>, TDoReturn, TUndoReturn>(actions: Actions<TPayload, TDoReturn, TUndoReturn>, options: Options<TPayload, NoInfer<TDoReturn>>): (payload: TPayload) => TDoReturn;
|
|
@@ -131,4 +139,4 @@ type BlockCommandArgs = {
|
|
|
131
139
|
};
|
|
132
140
|
declare function blockCommand({ command, condition }: BlockCommandArgs): DataHook;
|
|
133
141
|
|
|
134
|
-
export { type CommandEvent, type CommandEventDescriptor, type EditMode, type EventDescriptor, type ExtendedWindow, type HistoryItem, type ListenerCallback, type ListenerEvent, type RouteEvent, type RouteEventDescriptor, type UseRouteStatusOptions, type WindowEvent, type WindowEventDescriptor, type WindowWithHistoryManager, dispatchReadyEvent as __privateDispatchReadyEvent, flushListeners as __privateFlushListeners, isRouteActive as __privateIsRouteActive, listenTo as __privateListenTo, openRoute as __privateOpenRoute, registerRoute as __privateRegisterRoute, runCommand as __privateRunCommand, runCommandSync as __privateRunCommandSync, setReady as __privateSetReady, useIsRouteActive as __privateUseIsRouteActive, useListenTo as __privateUseListenTo, useRouteStatus as __privateUseRouteStatus, blockCommand, changeEditMode, commandEndEvent, commandStartEvent, dispatchReadyEvent, flushListeners, isExperimentActive, isReady, listenTo, registerDataHook, routeCloseEvent, routeOpenEvent, setReady, undoable, useEditMode, v1ReadyEvent, windowEvent };
|
|
142
|
+
export { type CommandEvent, type CommandEventDescriptor, EXPERIMENTAL_FEATURES, type EditMode, type EventDescriptor, type ExtendedWindow, type HistoryItem, type ListenerCallback, type ListenerEvent, type RouteEvent, type RouteEventDescriptor, type UseRouteStatusOptions, type WindowEvent, type WindowEventDescriptor, type WindowWithHistoryManager, dispatchReadyEvent as __privateDispatchReadyEvent, flushListeners as __privateFlushListeners, isRouteActive as __privateIsRouteActive, listenTo as __privateListenTo, openRoute as __privateOpenRoute, registerRoute as __privateRegisterRoute, runCommand as __privateRunCommand, runCommandSync as __privateRunCommandSync, setReady as __privateSetReady, useIsRouteActive as __privateUseIsRouteActive, useListenTo as __privateUseListenTo, useRouteStatus as __privateUseRouteStatus, blockCommand, changeEditMode, commandEndEvent, commandStartEvent, dispatchReadyEvent, flushListeners, isExperimentActive, isReady, listenTo, registerDataHook, routeCloseEvent, routeOpenEvent, setReady, undoable, useEditMode, v1ReadyEvent, windowEvent };
|
package/dist/index.js
CHANGED
|
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
+
EXPERIMENTAL_FEATURES: () => EXPERIMENTAL_FEATURES,
|
|
23
24
|
__privateDispatchReadyEvent: () => dispatchReadyEvent,
|
|
24
25
|
__privateFlushListeners: () => flushListeners,
|
|
25
26
|
__privateIsRouteActive: () => isRouteActive,
|
|
@@ -267,6 +268,11 @@ function makeEventHandler(event) {
|
|
|
267
268
|
}
|
|
268
269
|
|
|
269
270
|
// src/readers/index.ts
|
|
271
|
+
var EXPERIMENTAL_FEATURES = {
|
|
272
|
+
CUSTOM_CSS: "atomic_custom_css",
|
|
273
|
+
TRANSITIONS: "atomic_widgets_should_use_transition",
|
|
274
|
+
UNSTABLE_REPEATER: "e_unstable_repeater"
|
|
275
|
+
};
|
|
270
276
|
function isRouteActive(route) {
|
|
271
277
|
const extendedWindow = window;
|
|
272
278
|
return !!extendedWindow.$e?.routes?.isPartOf(route);
|
|
@@ -323,6 +329,9 @@ function useRouteStatus(route, { blockOnKitRoutes = true, allowedEditModes = ["e
|
|
|
323
329
|
};
|
|
324
330
|
}
|
|
325
331
|
|
|
332
|
+
// src/undoable/undoable.ts
|
|
333
|
+
var import_utils5 = require("@elementor/utils");
|
|
334
|
+
|
|
326
335
|
// src/undoable/get-history-manager.ts
|
|
327
336
|
var import_utils4 = require("@elementor/utils");
|
|
328
337
|
var HistoryManagerNotAvailable = (0, import_utils4.createError)({
|
|
@@ -341,12 +350,12 @@ function getHistoryManager() {
|
|
|
341
350
|
// src/undoable/undoable.ts
|
|
342
351
|
function undoable(actions, options) {
|
|
343
352
|
actions.redo ??= actions.do;
|
|
353
|
+
const _addHistoryItem = options.debounce ? (0, import_utils5.debounce)(addHistoryItem, options.debounce.wait) : addHistoryItem;
|
|
344
354
|
return (payload) => {
|
|
345
355
|
const _payload = payload;
|
|
346
356
|
const _actions = actions;
|
|
347
|
-
const history = getHistoryManager();
|
|
348
357
|
let result = _actions.do(_payload);
|
|
349
|
-
|
|
358
|
+
_addHistoryItem({
|
|
350
359
|
title: normalizeToGenerator(options.title)(_payload, result),
|
|
351
360
|
subTitle: normalizeToGenerator(options.subtitle)(_payload, result),
|
|
352
361
|
type: "",
|
|
@@ -364,6 +373,10 @@ function undoable(actions, options) {
|
|
|
364
373
|
function normalizeToGenerator(value) {
|
|
365
374
|
return typeof value === "function" ? value : () => value ?? "";
|
|
366
375
|
}
|
|
376
|
+
function addHistoryItem(item) {
|
|
377
|
+
const history = getHistoryManager();
|
|
378
|
+
history.addItem(item);
|
|
379
|
+
}
|
|
367
380
|
|
|
368
381
|
// src/data-hooks/register-data-hook.ts
|
|
369
382
|
var hookId = 0;
|
|
@@ -403,6 +416,7 @@ function blockCommand({ command, condition }) {
|
|
|
403
416
|
}
|
|
404
417
|
// Annotate the CommonJS export names for ESM import in node:
|
|
405
418
|
0 && (module.exports = {
|
|
419
|
+
EXPERIMENTAL_FEATURES,
|
|
406
420
|
__privateDispatchReadyEvent,
|
|
407
421
|
__privateFlushListeners,
|
|
408
422
|
__privateIsRouteActive,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/dispatchers/utils.ts","../src/dispatchers/dispatchers.ts","../src/listeners/event-creators.ts","../src/listeners/is-ready.ts","../src/listeners/utils.ts","../src/listeners/listeners.ts","../src/readers/index.ts","../src/hooks/use-listen-to.ts","../src/hooks/use-is-route-active.ts","../src/edit-mode.ts","../src/hooks/use-route-status.ts","../src/undoable/get-history-manager.ts","../src/undoable/undoable.ts","../src/data-hooks/register-data-hook.ts","../src/data-hooks/block-command.ts"],"sourcesContent":["export {\n\trunCommand as __privateRunCommand,\n\trunCommandSync as __privateRunCommandSync,\n\topenRoute as __privateOpenRoute,\n\tregisterRoute as __privateRegisterRoute,\n} from './dispatchers/dispatchers';\n\nexport {\n\tuseIsRouteActive as __privateUseIsRouteActive,\n\tuseListenTo as __privateUseListenTo,\n\tuseRouteStatus as __privateUseRouteStatus,\n\ttype UseRouteStatusOptions,\n} from './hooks';\n\nexport {\n\tsetReady as __privateSetReady,\n\tlistenTo as __privateListenTo,\n\tflushListeners as __privateFlushListeners,\n\tdispatchReadyEvent as __privateDispatchReadyEvent,\n\twindowEvent,\n\tv1ReadyEvent,\n\tcommandStartEvent,\n\tcommandEndEvent,\n\trouteOpenEvent,\n\trouteCloseEvent,\n} from './listeners';\n\nexport type * from './listeners';\n\nexport { isRouteActive as __privateIsRouteActive, isExperimentActive } from './readers';\n\nexport { undoable } from './undoable';\n\nexport type { HistoryItem, WindowWithHistoryManager } from './undoable/get-history-manager';\n\nexport { useEditMode, changeEditMode, type EditMode } from './edit-mode';\n\nexport { registerDataHook } from './data-hooks/register-data-hook';\nexport { blockCommand } from './data-hooks/block-command';\n","import { type jQueryDeferred } from './types';\n\nexport function isJQueryDeferred< T >( value: unknown ): value is jQueryDeferred< T > {\n\t// TODO: Copied from:\n\t// https://github.com/elementor/elementor/blob/6a74fc9/modules/web-cli/assets/js/core/commands.js#L410\n\n\treturn (\n\t\t!! value &&\n\t\t'object' === typeof value &&\n\t\tObject.hasOwn( value, 'promise' ) &&\n\t\tObject.hasOwn( value, 'then' ) &&\n\t\tObject.hasOwn( value, 'fail' )\n\t);\n}\n\nexport function promisifyJQueryDeferred< T >( deferred: jQueryDeferred< T > ): Promise< T > {\n\treturn new Promise( ( resolve, reject ) => {\n\t\tdeferred.then( resolve, reject );\n\t} );\n}\n","import { type ExtendedWindow } from './types';\nimport { isJQueryDeferred, promisifyJQueryDeferred } from './utils';\n\ntype RunCommandOptions = {\n\tinternal?: boolean;\n};\n\nexport async function runCommand( command: string, args?: object, { internal = false }: RunCommandOptions = {} ) {\n\tconst result = runCommandSync( command, args, { internal } );\n\n\tif ( result instanceof Promise ) {\n\t\treturn result;\n\t}\n\n\tif ( isJQueryDeferred( result ) ) {\n\t\treturn promisifyJQueryDeferred( result );\n\t}\n\n\treturn Promise.resolve( result );\n}\n\nexport function runCommandSync( command: string, args?: object, { internal = false }: RunCommandOptions = {} ) {\n\tconst extendedWindow = window as unknown as ExtendedWindow;\n\n\tconst run = internal ? extendedWindow.$e?.internal : extendedWindow.$e?.run;\n\n\tif ( ! run ) {\n\t\tconst runnerName = internal ? '$e.internal' : '$e.run';\n\n\t\tthrow new Error( `\\`${ runnerName }()\\` is not available` );\n\t}\n\n\treturn run( command, args );\n}\n\nexport function openRoute( route: string ) {\n\tconst extendedWindow = window as unknown as ExtendedWindow;\n\n\tif ( ! extendedWindow.$e?.route ) {\n\t\treturn Promise.reject( '`$e.route()` is not available' );\n\t}\n\n\ttry {\n\t\treturn Promise.resolve( extendedWindow.$e.route( route ) );\n\t} catch ( e ) {\n\t\treturn Promise.reject( e );\n\t}\n}\n\nexport function registerRoute( route: string ) {\n\tconst extendedWindow = window as unknown as ExtendedWindow;\n\n\tif ( ! extendedWindow.$e?.routes?.register ) {\n\t\treturn Promise.reject( '`$e.routes.register()` is not available' );\n\t}\n\n\tconst routeParts = route.split( '/' );\n\n\tif ( routeParts.length < 2 ) {\n\t\treturn Promise.reject( `\\`${ route }\\` is an invalid route` );\n\t}\n\n\tconst componentRoute = routeParts.pop() as string; // routeParts.length must be >= 2\n\tconst component = routeParts.join( '/' );\n\n\ttry {\n\t\treturn Promise.resolve( extendedWindow.$e.routes.register( component, componentRoute, () => null ) );\n\t} catch ( e ) {\n\t\treturn Promise.reject( e );\n\t}\n}\n","import { type CommandEventDescriptor, type RouteEventDescriptor, type WindowEventDescriptor } from './types';\n\nexport const commandStartEvent = ( command: CommandEventDescriptor[ 'name' ] ): CommandEventDescriptor => {\n\treturn {\n\t\ttype: 'command',\n\t\tname: command,\n\t\tstate: 'before',\n\t};\n};\n\nexport const commandEndEvent = ( command: CommandEventDescriptor[ 'name' ] ): CommandEventDescriptor => {\n\treturn {\n\t\ttype: 'command',\n\t\tname: command,\n\t\tstate: 'after',\n\t};\n};\n\nexport const routeOpenEvent = ( route: RouteEventDescriptor[ 'name' ] ): RouteEventDescriptor => {\n\treturn {\n\t\ttype: 'route',\n\t\tname: route,\n\t\tstate: 'open',\n\t};\n};\n\nexport const routeCloseEvent = ( route: RouteEventDescriptor[ 'name' ] ): RouteEventDescriptor => {\n\treturn {\n\t\ttype: 'route',\n\t\tname: route,\n\t\tstate: 'close',\n\t};\n};\n\nexport const windowEvent = ( event: WindowEventDescriptor[ 'name' ] ): WindowEventDescriptor => {\n\treturn {\n\t\ttype: 'window-event',\n\t\tname: event,\n\t};\n};\n\nexport const v1ReadyEvent = () => {\n\treturn windowEvent( 'elementor/initialized' );\n};\n","/**\n * This file is used to store the state of the isReady variable, which is used to determine\n * if the adapter is ready to receive events (editor v1 and v2 are loaded).\n */\n\nlet ready = false;\n\nexport function isReady() {\n\treturn ready;\n}\n\nexport function setReady( value: boolean ) {\n\tready = value;\n}\n","import { setReady } from './is-ready';\nimport { type ExtendedWindow, type ListenerEvent } from './types';\n\nexport function dispatchReadyEvent() {\n\treturn getV1LoadingPromise().then( () => {\n\t\tsetReady( true );\n\t\twindow.dispatchEvent( new CustomEvent( 'elementor/initialized' ) );\n\t} );\n}\n\nfunction getV1LoadingPromise() {\n\tconst v1LoadingPromise = ( window as unknown as ExtendedWindow ).__elementorEditorV1LoadingPromise;\n\n\tif ( ! v1LoadingPromise ) {\n\t\treturn Promise.reject( 'Elementor Editor V1 is not loaded' );\n\t}\n\n\treturn v1LoadingPromise;\n}\n\nexport function normalizeEvent( e: ListenerEvent[ 'originalEvent' ] ): ListenerEvent {\n\tif ( e instanceof CustomEvent && e.detail?.command ) {\n\t\treturn {\n\t\t\ttype: 'command',\n\t\t\tcommand: e.detail.command,\n\t\t\targs: e.detail.args,\n\t\t\toriginalEvent: e,\n\t\t};\n\t}\n\n\tif ( e instanceof CustomEvent && e.detail?.route ) {\n\t\treturn {\n\t\t\ttype: 'route',\n\t\t\troute: e.detail.route,\n\t\t\toriginalEvent: e,\n\t\t};\n\t}\n\n\treturn {\n\t\ttype: 'window-event',\n\t\tevent: e.type,\n\t\toriginalEvent: e,\n\t};\n}\n","import { isReady, setReady } from './is-ready';\nimport {\n\ttype CommandEventDescriptor,\n\ttype EventDescriptor,\n\ttype ListenerCallback,\n\ttype RouteEventDescriptor,\n\ttype WindowEventDescriptor,\n} from './types';\nimport { normalizeEvent } from './utils';\n\nconst callbacksByEvent = new Map< EventDescriptor[ 'name' ], ListenerCallback[] >();\nlet abortController = new AbortController();\n\nexport function listenTo( eventDescriptors: EventDescriptor | EventDescriptor[], callback: ListenerCallback ) {\n\tif ( ! Array.isArray( eventDescriptors ) ) {\n\t\teventDescriptors = [ eventDescriptors ];\n\t}\n\n\t// @see https://github.com/typescript-eslint/typescript-eslint/issues/2841\n\t// eslint-disable-next-line array-callback-return -- Clashes with typescript.\n\tconst cleanups = eventDescriptors.map( ( event ) => {\n\t\tconst { type, name } = event;\n\n\t\tswitch ( type ) {\n\t\t\tcase 'command':\n\t\t\t\treturn registerCommandListener( name, event.state, callback );\n\n\t\t\tcase 'route':\n\t\t\t\treturn registerRouteListener( name, event.state, callback );\n\n\t\t\tcase 'window-event':\n\t\t\t\treturn registerWindowEventListener( name, callback );\n\t\t}\n\t} );\n\n\treturn () => {\n\t\tcleanups.forEach( ( cleanup ) => cleanup() );\n\t};\n}\n\nexport function flushListeners() {\n\tabortController.abort();\n\tcallbacksByEvent.clear();\n\tsetReady( false );\n\n\tabortController = new AbortController();\n}\n\nfunction registerCommandListener(\n\tcommand: CommandEventDescriptor[ 'name' ],\n\tstate: CommandEventDescriptor[ 'state' ],\n\tcallback: ListenerCallback\n) {\n\treturn registerWindowEventListener( `elementor/commands/run/${ state }`, ( e ) => {\n\t\tconst shouldRunCallback = e.type === 'command' && e.command === command;\n\n\t\tif ( shouldRunCallback ) {\n\t\t\tcallback( e );\n\t\t}\n\t} );\n}\n\nfunction registerRouteListener(\n\troute: RouteEventDescriptor[ 'name' ],\n\tstate: RouteEventDescriptor[ 'state' ],\n\tcallback: ListenerCallback\n) {\n\treturn registerWindowEventListener( `elementor/routes/${ state }`, ( e ) => {\n\t\tconst shouldRunCallback = e.type === 'route' && e.route.startsWith( route );\n\n\t\tif ( shouldRunCallback ) {\n\t\t\tcallback( e );\n\t\t}\n\t} );\n}\n\nfunction registerWindowEventListener( event: WindowEventDescriptor[ 'name' ], callback: ListenerCallback ) {\n\tconst isFirstListener = ! callbacksByEvent.has( event );\n\n\tif ( isFirstListener ) {\n\t\tcallbacksByEvent.set( event, [] );\n\n\t\taddListener( event );\n\t}\n\n\tcallbacksByEvent.get( event )?.push( callback );\n\n\treturn () => {\n\t\tconst callbacks = callbacksByEvent.get( event );\n\n\t\tif ( ! callbacks?.length ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst filtered = callbacks.filter( ( cb ) => cb !== callback );\n\n\t\tcallbacksByEvent.set( event, filtered );\n\t};\n}\n\nfunction addListener( event: EventDescriptor[ 'name' ] ) {\n\twindow.addEventListener( event, makeEventHandler( event ), { signal: abortController.signal } );\n}\n\nfunction makeEventHandler( event: EventDescriptor[ 'name' ] ): EventListener {\n\treturn ( e ) => {\n\t\tif ( ! isReady() ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst normalizedEvent = normalizeEvent( e );\n\n\t\tcallbacksByEvent.get( event )?.forEach( ( callback ) => {\n\t\t\tcallback( normalizedEvent );\n\t\t} );\n\t};\n}\n","import { type ExtendedWindow } from './types';\n\nexport function isRouteActive( route: string ) {\n\tconst extendedWindow = window as unknown as ExtendedWindow;\n\n\treturn !! extendedWindow.$e?.routes?.isPartOf( route );\n}\n\nexport const isExperimentActive = ( experiment: string ) => {\n\tconst extendedWindow = window as unknown as ExtendedWindow;\n\n\treturn !! extendedWindow.elementorCommon?.config?.experimentalFeatures?.[ experiment ];\n};\n","import { useEffect, useState } from 'react';\n\nimport { type EventDescriptor, listenTo } from '../listeners';\n\nexport default function useListenTo< T >(\n\tevent: EventDescriptor | EventDescriptor[],\n\tgetSnapshot: () => T,\n\tdeps: unknown[] = []\n) {\n\tconst [ snapshot, setSnapshot ] = useState( () => getSnapshot() );\n\n\tuseEffect( () => {\n\t\tconst updateState = () => setSnapshot( getSnapshot() );\n\n\t\t// Ensure the state is re-calculated when the dependencies have been changed.\n\t\tupdateState();\n\n\t\treturn listenTo( event, updateState );\n\t}, deps ); // eslint-disable-line react-hooks/exhaustive-deps\n\n\treturn snapshot;\n}\n","import { routeCloseEvent, type RouteEventDescriptor, routeOpenEvent } from '../listeners';\nimport { isRouteActive } from '../readers';\nimport useListenTo from './use-listen-to';\n\nexport default function useIsRouteActive( route: RouteEventDescriptor[ 'name' ] ) {\n\treturn useListenTo( [ routeOpenEvent( route ), routeCloseEvent( route ) ], () => isRouteActive( route ), [\n\t\troute,\n\t] );\n}\n","import useListenTo from './hooks/use-listen-to';\nimport { windowEvent } from './listeners';\n\nexport type EditMode = 'edit' | 'preview' | 'picker' | ( string & {} );\n\nexport type ExtendedWindow = Window & {\n\telementor: {\n\t\tchangeEditMode: ( newMode: EditMode ) => void;\n\t\tchannels: {\n\t\t\tdataEditMode: {\n\t\t\t\trequest: ( key: 'activeMode' ) => EditMode;\n\t\t\t};\n\t\t};\n\t};\n};\n\nexport function useEditMode() {\n\treturn useListenTo( windowEvent( 'elementor/edit-mode/change' ), getCurrentEditMode );\n}\n\nfunction getCurrentEditMode() {\n\tconst extendedWindow = window as unknown as ExtendedWindow;\n\n\treturn extendedWindow.elementor.channels.dataEditMode.request( 'activeMode' );\n}\n\nexport function changeEditMode( newMode: EditMode ) {\n\tconst extendedWindow = window as unknown as ExtendedWindow;\n\n\treturn extendedWindow.elementor.changeEditMode( newMode );\n}\n","import { type EditMode, useEditMode } from '../edit-mode';\nimport { type RouteEventDescriptor } from '../listeners';\nimport useIsRouteActive from './use-is-route-active';\n\nexport type UseRouteStatusOptions = {\n\tblockOnKitRoutes?: boolean;\n\tallowedEditModes?: EditMode[];\n};\n\nexport default function useRouteStatus(\n\troute: RouteEventDescriptor[ 'name' ],\n\t{ blockOnKitRoutes = true, allowedEditModes = [ 'edit' ] }: UseRouteStatusOptions = {}\n) {\n\tconst isRouteActive = useIsRouteActive( route );\n\tconst isKitRouteActive = useIsRouteActive( 'panel/global' );\n\tconst currentEditMode = useEditMode();\n\n\tconst isBlockedByEditMode = ! allowedEditModes.includes( currentEditMode );\n\n\tconst isBlockedByKit = blockOnKitRoutes && isKitRouteActive;\n\n\tconst isActive = isRouteActive && ! isBlockedByEditMode;\n\n\tconst isBlocked = isBlockedByEditMode || isBlockedByKit;\n\n\treturn {\n\t\tisActive,\n\t\tisBlocked,\n\t};\n}\n","import { createError } from '@elementor/utils';\n\nexport type HistoryItem = {\n\ttitle: string;\n\tsubTitle: string;\n\ttype: string;\n\trestore: ( item: HistoryItem, isRedo: boolean ) => void;\n};\n\ntype AddHistoryItem = ( item: HistoryItem ) => void;\n\nexport type WindowWithHistoryManager = Window & {\n\telementor?: {\n\t\tdocuments?: {\n\t\t\tgetCurrent?: () => {\n\t\t\t\thistory?: {\n\t\t\t\t\taddItem: AddHistoryItem;\n\t\t\t\t};\n\t\t\t};\n\t\t};\n\t};\n};\n\nconst HistoryManagerNotAvailable = createError( {\n\tcode: 'history_manager_not_available',\n\tmessage: 'Cannot access History manager.',\n} );\n\nexport function getHistoryManager() {\n\tconst extendedWindow = window as unknown as WindowWithHistoryManager;\n\n\tconst historyManger = extendedWindow.elementor?.documents?.getCurrent?.()?.history;\n\n\tif ( ! historyManger ) {\n\t\tthrow new HistoryManagerNotAvailable();\n\t}\n\n\treturn historyManger;\n}\n","import { getHistoryManager } from './get-history-manager';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Payload = Record< string, any > | undefined;\n\ntype LabelGenerator< TPayload extends Payload, TDoReturn > = ( payload: TPayload, doReturn: TDoReturn ) => string;\n\ntype Actions< TPayload extends Payload, TDoReturn, TUndoReturn > = {\n\tdo: ( payload: TPayload ) => Awaited< TDoReturn >;\n\tundo: ( payload: TPayload, doReturn: Awaited< TDoReturn > ) => Awaited< TUndoReturn >;\n\tredo?: ( payload: TPayload, doReturn: Awaited< TDoReturn > ) => Awaited< TDoReturn >;\n};\n\ntype Options< TPayload extends Payload, TDoReturn > = {\n\ttitle: string | LabelGenerator< TPayload, TDoReturn >;\n\tsubtitle?: string | LabelGenerator< TPayload, TDoReturn >;\n};\n\n// Action WITHOUT a payload.\nexport function undoable< TDoReturn, TUndoReturn >(\n\tactions: Actions< undefined, TDoReturn, TUndoReturn >,\n\toptions: Options< undefined, NoInfer< TDoReturn > >\n): () => TDoReturn;\n\n// Action WITH a payload.\nexport function undoable< TPayload extends NonNullable< Payload >, TDoReturn, TUndoReturn >(\n\tactions: Actions< TPayload, TDoReturn, TUndoReturn >,\n\toptions: Options< TPayload, NoInfer< TDoReturn > >\n): ( payload: TPayload ) => TDoReturn;\n\nexport function undoable< TPayload extends Payload, TDoReturn, TUndoReturn >(\n\tactions: Actions< TPayload, TDoReturn, TUndoReturn >,\n\toptions: Options< TPayload, NoInfer< TDoReturn > >\n): ( payload?: Payload ) => TDoReturn {\n\tactions.redo ??= actions.do;\n\n\treturn ( payload ) => {\n\t\tconst _payload = payload as TPayload;\n\t\tconst _actions = actions as Required< Actions< TPayload, TDoReturn, TUndoReturn > >;\n\n\t\tconst history = getHistoryManager();\n\n\t\tlet result = _actions.do( _payload );\n\n\t\thistory.addItem( {\n\t\t\ttitle: normalizeToGenerator( options.title )( _payload, result ),\n\t\t\tsubTitle: normalizeToGenerator( options.subtitle )( _payload, result ),\n\t\t\ttype: '',\n\t\t\trestore: ( _, isRedo ) => {\n\t\t\t\tif ( isRedo ) {\n\t\t\t\t\tresult = _actions.redo( _payload, result );\n\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t_actions.undo( _payload, result );\n\t\t\t},\n\t\t} );\n\n\t\treturn result;\n\t};\n}\n\nfunction normalizeToGenerator< TPayload extends Payload, TDoReturn >(\n\tvalue: string | undefined | LabelGenerator< TPayload, TDoReturn >\n) {\n\treturn typeof value === 'function' ? value : () => value ?? '';\n}\n","export type WindowWithDataHooks = Window & {\n\t$e: {\n\t\tmodules?: {\n\t\t\thookData?: {\n\t\t\t\t[ K in keyof HooksMap as Capitalize< K > ]: HooksMap[ K ];\n\t\t\t};\n\t\t};\n\t};\n};\n\ntype HooksMap = Record< HookType, typeof DataHook | undefined >;\n\ntype HookType = 'after' | 'dependency';\n\nexport type Args = Record< string, unknown >;\n\nexport declare class DataHook {\n\tgetCommand(): string;\n\tgetId(): string;\n\tapply( args: Args ): unknown;\n\tregister(): void;\n}\n\nlet hookId = 0;\n\nexport function registerDataHook( type: 'dependency', command: string, callback: ( args: Args ) => boolean ): DataHook;\n\nexport function registerDataHook(\n\ttype: 'after',\n\tcommand: string,\n\tcallback: ( args: Args ) => void | Promise< void >\n): DataHook;\n\nexport function registerDataHook( type: HookType, command: string, callback: ( args: Args ) => unknown ): DataHook {\n\tconst eWindow = window as unknown as WindowWithDataHooks;\n\tconst hooksClasses = eWindow.$e?.modules?.hookData;\n\n\tconst hooksMap = {\n\t\tafter: hooksClasses?.After,\n\t\tdependency: hooksClasses?.Dependency,\n\t} satisfies HooksMap;\n\n\tconst HookClass = hooksMap[ type ];\n\n\tif ( ! HookClass ) {\n\t\tthrow new Error( `Data hook '${ type }' is not available` );\n\t}\n\n\tconst currentHookId = ++hookId;\n\n\tconst hook = new ( class extends HookClass {\n\t\tgetCommand() {\n\t\t\treturn command;\n\t\t}\n\n\t\tgetId() {\n\t\t\treturn `${ command }--data--${ currentHookId }`;\n\t\t}\n\n\t\tapply( args: Args ) {\n\t\t\treturn callback( args );\n\t\t}\n\t} )();\n\n\thook.register();\n\n\treturn hook;\n}\n","import { type Args, registerDataHook } from './register-data-hook';\n\ntype BlockCommandArgs = {\n\tcommand: string;\n\tcondition: ( args: Args ) => boolean;\n};\n\nexport function blockCommand( { command, condition }: BlockCommandArgs ) {\n\treturn registerDataHook( 'dependency', command, ( args ) => {\n\t\tconst shouldBlock = condition( args );\n\n\t\t// Should return `false` to prevent the command from running.\n\t\treturn ! shouldBlock;\n\t} );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEO,SAAS,iBAAuB,OAA+C;AAIrF,SACC,CAAC,CAAE,SACH,aAAa,OAAO,SACpB,OAAO,OAAQ,OAAO,SAAU,KAChC,OAAO,OAAQ,OAAO,MAAO,KAC7B,OAAO,OAAQ,OAAO,MAAO;AAE/B;AAEO,SAAS,wBAA8B,UAA8C;AAC3F,SAAO,IAAI,QAAS,CAAE,SAAS,WAAY;AAC1C,aAAS,KAAM,SAAS,MAAO;AAAA,EAChC,CAAE;AACH;;;ACZA,eAAsB,WAAY,SAAiB,MAAe,EAAE,WAAW,MAAM,IAAuB,CAAC,GAAI;AAChH,QAAM,SAAS,eAAgB,SAAS,MAAM,EAAE,SAAS,CAAE;AAE3D,MAAK,kBAAkB,SAAU;AAChC,WAAO;AAAA,EACR;AAEA,MAAK,iBAAkB,MAAO,GAAI;AACjC,WAAO,wBAAyB,MAAO;AAAA,EACxC;AAEA,SAAO,QAAQ,QAAS,MAAO;AAChC;AAEO,SAAS,eAAgB,SAAiB,MAAe,EAAE,WAAW,MAAM,IAAuB,CAAC,GAAI;AAC9G,QAAM,iBAAiB;AAEvB,QAAM,MAAM,WAAW,eAAe,IAAI,WAAW,eAAe,IAAI;AAExE,MAAK,CAAE,KAAM;AACZ,UAAM,aAAa,WAAW,gBAAgB;AAE9C,UAAM,IAAI,MAAO,K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,mBAAS,SAAS,KAAM,UAAU,MAAO;AAEzC;AAAA,QACD;AAEA,iBAAS,KAAM,UAAU,MAAO;AAAA,MACjC;AAAA,IACD,CAAE;AAEF,WAAO;AAAA,EACR;AACD;AAEA,SAAS,qBACR,OACC;AACD,SAAO,OAAO,UAAU,aAAa,QAAQ,MAAM,SAAS;AAC7D;;;AC5CA,IAAI,SAAS;AAUN,SAAS,iBAAkB,MAAgB,SAAiB,UAAgD;AAClH,QAAM,UAAU;AAChB,QAAM,eAAe,QAAQ,IAAI,SAAS;AAE1C,QAAM,WAAW;AAAA,IAChB,OAAO,cAAc;AAAA,IACrB,YAAY,cAAc;AAAA,EAC3B;AAEA,QAAM,YAAY,SAAU,IAAK;AAEjC,MAAK,CAAE,WAAY;AAClB,UAAM,IAAI,MAAO,cAAe,IAAK,oBAAqB;AAAA,EAC3D;AAEA,QAAM,gBAAgB,EAAE;AAExB,QAAM,OAAO,IAAM,cAAc,UAAU;AAAA,IAC1C,aAAa;AACZ,aAAO;AAAA,IACR;AAAA,IAEA,QAAQ;AACP,aAAO,GAAI,OAAQ,WAAY,aAAc;AAAA,IAC9C;AAAA,IAEA,MAAO,MAAa;AACnB,aAAO,SAAU,IAAK;AAAA,IACvB;AAAA,EACD,EAAI;AAEJ,OAAK,SAAS;AAEd,SAAO;AACR;;;AC5DO,SAAS,aAAc,EAAE,SAAS,UAAU,GAAsB;AACxE,SAAO,iBAAkB,cAAc,SAAS,CAAE,SAAU;AAC3D,UAAM,cAAc,UAAW,IAAK;AAGpC,WAAO,CAAE;AAAA,EACV,CAAE;AACH;","names":["isRouteActive","import_utils"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/dispatchers/utils.ts","../src/dispatchers/dispatchers.ts","../src/listeners/event-creators.ts","../src/listeners/is-ready.ts","../src/listeners/utils.ts","../src/listeners/listeners.ts","../src/readers/index.ts","../src/hooks/use-listen-to.ts","../src/hooks/use-is-route-active.ts","../src/edit-mode.ts","../src/hooks/use-route-status.ts","../src/undoable/undoable.ts","../src/undoable/get-history-manager.ts","../src/data-hooks/register-data-hook.ts","../src/data-hooks/block-command.ts"],"sourcesContent":["export {\n\trunCommand as __privateRunCommand,\n\trunCommandSync as __privateRunCommandSync,\n\topenRoute as __privateOpenRoute,\n\tregisterRoute as __privateRegisterRoute,\n} from './dispatchers/dispatchers';\n\nexport {\n\tuseIsRouteActive as __privateUseIsRouteActive,\n\tuseListenTo as __privateUseListenTo,\n\tuseRouteStatus as __privateUseRouteStatus,\n\ttype UseRouteStatusOptions,\n} from './hooks';\n\nexport {\n\tsetReady as __privateSetReady,\n\tlistenTo as __privateListenTo,\n\tflushListeners as __privateFlushListeners,\n\tdispatchReadyEvent as __privateDispatchReadyEvent,\n\twindowEvent,\n\tv1ReadyEvent,\n\tcommandStartEvent,\n\tcommandEndEvent,\n\trouteOpenEvent,\n\trouteCloseEvent,\n} from './listeners';\n\nexport type * from './listeners';\n\nexport { isRouteActive as __privateIsRouteActive, isExperimentActive, EXPERIMENTAL_FEATURES } from './readers';\n\nexport { undoable } from './undoable';\n\nexport type { HistoryItem, WindowWithHistoryManager } from './undoable/get-history-manager';\n\nexport { useEditMode, changeEditMode, type EditMode } from './edit-mode';\n\nexport { registerDataHook } from './data-hooks/register-data-hook';\nexport { blockCommand } from './data-hooks/block-command';\n","import { type jQueryDeferred } from './types';\n\nexport function isJQueryDeferred< T >( value: unknown ): value is jQueryDeferred< T > {\n\t// TODO: Copied from:\n\t// https://github.com/elementor/elementor/blob/6a74fc9/modules/web-cli/assets/js/core/commands.js#L410\n\n\treturn (\n\t\t!! value &&\n\t\t'object' === typeof value &&\n\t\tObject.hasOwn( value, 'promise' ) &&\n\t\tObject.hasOwn( value, 'then' ) &&\n\t\tObject.hasOwn( value, 'fail' )\n\t);\n}\n\nexport function promisifyJQueryDeferred< T >( deferred: jQueryDeferred< T > ): Promise< T > {\n\treturn new Promise( ( resolve, reject ) => {\n\t\tdeferred.then( resolve, reject );\n\t} );\n}\n","import { type ExtendedWindow } from './types';\nimport { isJQueryDeferred, promisifyJQueryDeferred } from './utils';\n\ntype RunCommandOptions = {\n\tinternal?: boolean;\n};\n\nexport async function runCommand( command: string, args?: object, { internal = false }: RunCommandOptions = {} ) {\n\tconst result = runCommandSync( command, args, { internal } );\n\n\tif ( result instanceof Promise ) {\n\t\treturn result;\n\t}\n\n\tif ( isJQueryDeferred( result ) ) {\n\t\treturn promisifyJQueryDeferred( result );\n\t}\n\n\treturn Promise.resolve( result );\n}\n\nexport function runCommandSync( command: string, args?: object, { internal = false }: RunCommandOptions = {} ) {\n\tconst extendedWindow = window as unknown as ExtendedWindow;\n\n\tconst run = internal ? extendedWindow.$e?.internal : extendedWindow.$e?.run;\n\n\tif ( ! run ) {\n\t\tconst runnerName = internal ? '$e.internal' : '$e.run';\n\n\t\tthrow new Error( `\\`${ runnerName }()\\` is not available` );\n\t}\n\n\treturn run( command, args );\n}\n\nexport function openRoute( route: string ) {\n\tconst extendedWindow = window as unknown as ExtendedWindow;\n\n\tif ( ! extendedWindow.$e?.route ) {\n\t\treturn Promise.reject( '`$e.route()` is not available' );\n\t}\n\n\ttry {\n\t\treturn Promise.resolve( extendedWindow.$e.route( route ) );\n\t} catch ( e ) {\n\t\treturn Promise.reject( e );\n\t}\n}\n\nexport function registerRoute( route: string ) {\n\tconst extendedWindow = window as unknown as ExtendedWindow;\n\n\tif ( ! extendedWindow.$e?.routes?.register ) {\n\t\treturn Promise.reject( '`$e.routes.register()` is not available' );\n\t}\n\n\tconst routeParts = route.split( '/' );\n\n\tif ( routeParts.length < 2 ) {\n\t\treturn Promise.reject( `\\`${ route }\\` is an invalid route` );\n\t}\n\n\tconst componentRoute = routeParts.pop() as string; // routeParts.length must be >= 2\n\tconst component = routeParts.join( '/' );\n\n\ttry {\n\t\treturn Promise.resolve( extendedWindow.$e.routes.register( component, componentRoute, () => null ) );\n\t} catch ( e ) {\n\t\treturn Promise.reject( e );\n\t}\n}\n","import { type CommandEventDescriptor, type RouteEventDescriptor, type WindowEventDescriptor } from './types';\n\nexport const commandStartEvent = ( command: CommandEventDescriptor[ 'name' ] ): CommandEventDescriptor => {\n\treturn {\n\t\ttype: 'command',\n\t\tname: command,\n\t\tstate: 'before',\n\t};\n};\n\nexport const commandEndEvent = ( command: CommandEventDescriptor[ 'name' ] ): CommandEventDescriptor => {\n\treturn {\n\t\ttype: 'command',\n\t\tname: command,\n\t\tstate: 'after',\n\t};\n};\n\nexport const routeOpenEvent = ( route: RouteEventDescriptor[ 'name' ] ): RouteEventDescriptor => {\n\treturn {\n\t\ttype: 'route',\n\t\tname: route,\n\t\tstate: 'open',\n\t};\n};\n\nexport const routeCloseEvent = ( route: RouteEventDescriptor[ 'name' ] ): RouteEventDescriptor => {\n\treturn {\n\t\ttype: 'route',\n\t\tname: route,\n\t\tstate: 'close',\n\t};\n};\n\nexport const windowEvent = ( event: WindowEventDescriptor[ 'name' ] ): WindowEventDescriptor => {\n\treturn {\n\t\ttype: 'window-event',\n\t\tname: event,\n\t};\n};\n\nexport const v1ReadyEvent = () => {\n\treturn windowEvent( 'elementor/initialized' );\n};\n","/**\n * This file is used to store the state of the isReady variable, which is used to determine\n * if the adapter is ready to receive events (editor v1 and v2 are loaded).\n */\n\nlet ready = false;\n\nexport function isReady() {\n\treturn ready;\n}\n\nexport function setReady( value: boolean ) {\n\tready = value;\n}\n","import { setReady } from './is-ready';\nimport { type ExtendedWindow, type ListenerEvent } from './types';\n\nexport function dispatchReadyEvent() {\n\treturn getV1LoadingPromise().then( () => {\n\t\tsetReady( true );\n\t\twindow.dispatchEvent( new CustomEvent( 'elementor/initialized' ) );\n\t} );\n}\n\nfunction getV1LoadingPromise() {\n\tconst v1LoadingPromise = ( window as unknown as ExtendedWindow ).__elementorEditorV1LoadingPromise;\n\n\tif ( ! v1LoadingPromise ) {\n\t\treturn Promise.reject( 'Elementor Editor V1 is not loaded' );\n\t}\n\n\treturn v1LoadingPromise;\n}\n\nexport function normalizeEvent( e: ListenerEvent[ 'originalEvent' ] ): ListenerEvent {\n\tif ( e instanceof CustomEvent && e.detail?.command ) {\n\t\treturn {\n\t\t\ttype: 'command',\n\t\t\tcommand: e.detail.command,\n\t\t\targs: e.detail.args,\n\t\t\toriginalEvent: e,\n\t\t};\n\t}\n\n\tif ( e instanceof CustomEvent && e.detail?.route ) {\n\t\treturn {\n\t\t\ttype: 'route',\n\t\t\troute: e.detail.route,\n\t\t\toriginalEvent: e,\n\t\t};\n\t}\n\n\treturn {\n\t\ttype: 'window-event',\n\t\tevent: e.type,\n\t\toriginalEvent: e,\n\t};\n}\n","import { isReady, setReady } from './is-ready';\nimport {\n\ttype CommandEventDescriptor,\n\ttype EventDescriptor,\n\ttype ListenerCallback,\n\ttype RouteEventDescriptor,\n\ttype WindowEventDescriptor,\n} from './types';\nimport { normalizeEvent } from './utils';\n\nconst callbacksByEvent = new Map< EventDescriptor[ 'name' ], ListenerCallback[] >();\nlet abortController = new AbortController();\n\nexport function listenTo( eventDescriptors: EventDescriptor | EventDescriptor[], callback: ListenerCallback ) {\n\tif ( ! Array.isArray( eventDescriptors ) ) {\n\t\teventDescriptors = [ eventDescriptors ];\n\t}\n\n\t// @see https://github.com/typescript-eslint/typescript-eslint/issues/2841\n\t// eslint-disable-next-line array-callback-return -- Clashes with typescript.\n\tconst cleanups = eventDescriptors.map( ( event ) => {\n\t\tconst { type, name } = event;\n\n\t\tswitch ( type ) {\n\t\t\tcase 'command':\n\t\t\t\treturn registerCommandListener( name, event.state, callback );\n\n\t\t\tcase 'route':\n\t\t\t\treturn registerRouteListener( name, event.state, callback );\n\n\t\t\tcase 'window-event':\n\t\t\t\treturn registerWindowEventListener( name, callback );\n\t\t}\n\t} );\n\n\treturn () => {\n\t\tcleanups.forEach( ( cleanup ) => cleanup() );\n\t};\n}\n\nexport function flushListeners() {\n\tabortController.abort();\n\tcallbacksByEvent.clear();\n\tsetReady( false );\n\n\tabortController = new AbortController();\n}\n\nfunction registerCommandListener(\n\tcommand: CommandEventDescriptor[ 'name' ],\n\tstate: CommandEventDescriptor[ 'state' ],\n\tcallback: ListenerCallback\n) {\n\treturn registerWindowEventListener( `elementor/commands/run/${ state }`, ( e ) => {\n\t\tconst shouldRunCallback = e.type === 'command' && e.command === command;\n\n\t\tif ( shouldRunCallback ) {\n\t\t\tcallback( e );\n\t\t}\n\t} );\n}\n\nfunction registerRouteListener(\n\troute: RouteEventDescriptor[ 'name' ],\n\tstate: RouteEventDescriptor[ 'state' ],\n\tcallback: ListenerCallback\n) {\n\treturn registerWindowEventListener( `elementor/routes/${ state }`, ( e ) => {\n\t\tconst shouldRunCallback = e.type === 'route' && e.route.startsWith( route );\n\n\t\tif ( shouldRunCallback ) {\n\t\t\tcallback( e );\n\t\t}\n\t} );\n}\n\nfunction registerWindowEventListener( event: WindowEventDescriptor[ 'name' ], callback: ListenerCallback ) {\n\tconst isFirstListener = ! callbacksByEvent.has( event );\n\n\tif ( isFirstListener ) {\n\t\tcallbacksByEvent.set( event, [] );\n\n\t\taddListener( event );\n\t}\n\n\tcallbacksByEvent.get( event )?.push( callback );\n\n\treturn () => {\n\t\tconst callbacks = callbacksByEvent.get( event );\n\n\t\tif ( ! callbacks?.length ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst filtered = callbacks.filter( ( cb ) => cb !== callback );\n\n\t\tcallbacksByEvent.set( event, filtered );\n\t};\n}\n\nfunction addListener( event: EventDescriptor[ 'name' ] ) {\n\twindow.addEventListener( event, makeEventHandler( event ), { signal: abortController.signal } );\n}\n\nfunction makeEventHandler( event: EventDescriptor[ 'name' ] ): EventListener {\n\treturn ( e ) => {\n\t\tif ( ! isReady() ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst normalizedEvent = normalizeEvent( e );\n\n\t\tcallbacksByEvent.get( event )?.forEach( ( callback ) => {\n\t\t\tcallback( normalizedEvent );\n\t\t} );\n\t};\n}\n","import { type ExtendedWindow } from './types';\n\nexport const EXPERIMENTAL_FEATURES = {\n\tCUSTOM_CSS: 'atomic_custom_css',\n\tTRANSITIONS: 'atomic_widgets_should_use_transition',\n\tUNSTABLE_REPEATER: 'e_unstable_repeater',\n};\n\nexport function isRouteActive( route: string ) {\n\tconst extendedWindow = window as unknown as ExtendedWindow;\n\n\treturn !! extendedWindow.$e?.routes?.isPartOf( route );\n}\n\nexport const isExperimentActive = ( experiment: keyof typeof EXPERIMENTAL_FEATURES | string ) => {\n\tconst extendedWindow = window as unknown as ExtendedWindow;\n\n\treturn !! extendedWindow.elementorCommon?.config?.experimentalFeatures?.[ experiment ];\n};\n","import { useEffect, useState } from 'react';\n\nimport { type EventDescriptor, listenTo } from '../listeners';\n\nexport default function useListenTo< T >(\n\tevent: EventDescriptor | EventDescriptor[],\n\tgetSnapshot: () => T,\n\tdeps: unknown[] = []\n) {\n\tconst [ snapshot, setSnapshot ] = useState( () => getSnapshot() );\n\n\tuseEffect( () => {\n\t\tconst updateState = () => setSnapshot( getSnapshot() );\n\n\t\t// Ensure the state is re-calculated when the dependencies have been changed.\n\t\tupdateState();\n\n\t\treturn listenTo( event, updateState );\n\t}, deps ); // eslint-disable-line react-hooks/exhaustive-deps\n\n\treturn snapshot;\n}\n","import { routeCloseEvent, type RouteEventDescriptor, routeOpenEvent } from '../listeners';\nimport { isRouteActive } from '../readers';\nimport useListenTo from './use-listen-to';\n\nexport default function useIsRouteActive( route: RouteEventDescriptor[ 'name' ] ) {\n\treturn useListenTo( [ routeOpenEvent( route ), routeCloseEvent( route ) ], () => isRouteActive( route ), [\n\t\troute,\n\t] );\n}\n","import useListenTo from './hooks/use-listen-to';\nimport { windowEvent } from './listeners';\n\nexport type EditMode = 'edit' | 'preview' | 'picker' | ( string & {} );\n\nexport type ExtendedWindow = Window & {\n\telementor: {\n\t\tchangeEditMode: ( newMode: EditMode ) => void;\n\t\tchannels: {\n\t\t\tdataEditMode: {\n\t\t\t\trequest: ( key: 'activeMode' ) => EditMode;\n\t\t\t};\n\t\t};\n\t};\n};\n\nexport function useEditMode() {\n\treturn useListenTo( windowEvent( 'elementor/edit-mode/change' ), getCurrentEditMode );\n}\n\nfunction getCurrentEditMode() {\n\tconst extendedWindow = window as unknown as ExtendedWindow;\n\n\treturn extendedWindow.elementor.channels.dataEditMode.request( 'activeMode' );\n}\n\nexport function changeEditMode( newMode: EditMode ) {\n\tconst extendedWindow = window as unknown as ExtendedWindow;\n\n\treturn extendedWindow.elementor.changeEditMode( newMode );\n}\n","import { type EditMode, useEditMode } from '../edit-mode';\nimport { type RouteEventDescriptor } from '../listeners';\nimport useIsRouteActive from './use-is-route-active';\n\nexport type UseRouteStatusOptions = {\n\tblockOnKitRoutes?: boolean;\n\tallowedEditModes?: EditMode[];\n};\n\nexport default function useRouteStatus(\n\troute: RouteEventDescriptor[ 'name' ],\n\t{ blockOnKitRoutes = true, allowedEditModes = [ 'edit' ] }: UseRouteStatusOptions = {}\n) {\n\tconst isRouteActive = useIsRouteActive( route );\n\tconst isKitRouteActive = useIsRouteActive( 'panel/global' );\n\tconst currentEditMode = useEditMode();\n\n\tconst isBlockedByEditMode = ! allowedEditModes.includes( currentEditMode );\n\n\tconst isBlockedByKit = blockOnKitRoutes && isKitRouteActive;\n\n\tconst isActive = isRouteActive && ! isBlockedByEditMode;\n\n\tconst isBlocked = isBlockedByEditMode || isBlockedByKit;\n\n\treturn {\n\t\tisActive,\n\t\tisBlocked,\n\t};\n}\n","import { debounce } from '@elementor/utils';\n\nimport { getHistoryManager, type HistoryItem } from './get-history-manager';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Payload = Record< string, any > | undefined;\n\ntype LabelGenerator< TPayload extends Payload, TDoReturn > = ( payload: TPayload, doReturn: TDoReturn ) => string;\n\ntype Actions< TPayload extends Payload, TDoReturn, TUndoReturn > = {\n\tdo: ( payload: TPayload ) => Awaited< TDoReturn >;\n\tundo: ( payload: TPayload, doReturn: Awaited< TDoReturn > ) => Awaited< TUndoReturn >;\n\tredo?: ( payload: TPayload, doReturn: Awaited< TDoReturn > ) => Awaited< TDoReturn >;\n};\n\ntype Options< TPayload extends Payload, TDoReturn > = {\n\ttitle: string | LabelGenerator< TPayload, TDoReturn >;\n\tsubtitle?: string | LabelGenerator< TPayload, TDoReturn >;\n\tdebounce?: { wait: number };\n};\n\n// Action WITHOUT a payload.\nexport function undoable< TDoReturn, TUndoReturn >(\n\tactions: Actions< undefined, TDoReturn, TUndoReturn >,\n\toptions: Options< undefined, NoInfer< TDoReturn > >\n): () => TDoReturn;\n\n// Action WITH a payload.\nexport function undoable< TPayload extends NonNullable< Payload >, TDoReturn, TUndoReturn >(\n\tactions: Actions< TPayload, TDoReturn, TUndoReturn >,\n\toptions: Options< TPayload, NoInfer< TDoReturn > >\n): ( payload: TPayload ) => TDoReturn;\n\nexport function undoable< TPayload extends Payload, TDoReturn, TUndoReturn >(\n\tactions: Actions< TPayload, TDoReturn, TUndoReturn >,\n\toptions: Options< TPayload, NoInfer< TDoReturn > >\n): ( payload?: Payload ) => TDoReturn {\n\tactions.redo ??= actions.do;\n\n\tconst _addHistoryItem = options.debounce ? debounce( addHistoryItem, options.debounce.wait ) : addHistoryItem;\n\n\treturn ( payload ) => {\n\t\tconst _payload = payload as TPayload;\n\t\tconst _actions = actions as Required< Actions< TPayload, TDoReturn, TUndoReturn > >;\n\n\t\tlet result = _actions.do( _payload );\n\n\t\t_addHistoryItem( {\n\t\t\ttitle: normalizeToGenerator( options.title )( _payload, result ),\n\t\t\tsubTitle: normalizeToGenerator( options.subtitle )( _payload, result ),\n\t\t\ttype: '',\n\t\t\trestore: ( _, isRedo ) => {\n\t\t\t\tif ( isRedo ) {\n\t\t\t\t\tresult = _actions.redo( _payload, result );\n\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t_actions.undo( _payload, result );\n\t\t\t},\n\t\t} );\n\n\t\treturn result;\n\t};\n}\n\nfunction normalizeToGenerator< TPayload extends Payload, TDoReturn >(\n\tvalue: string | undefined | LabelGenerator< TPayload, TDoReturn >\n) {\n\treturn typeof value === 'function' ? value : () => value ?? '';\n}\n\nfunction addHistoryItem( item: HistoryItem ) {\n\tconst history = getHistoryManager();\n\thistory.addItem( item );\n}\n","import { createError } from '@elementor/utils';\n\nexport type HistoryItem = {\n\ttitle: string;\n\tsubTitle: string;\n\ttype: string;\n\trestore: ( item: HistoryItem, isRedo: boolean ) => void;\n};\n\ntype AddHistoryItem = ( item: HistoryItem ) => void;\n\nexport type WindowWithHistoryManager = Window & {\n\telementor?: {\n\t\tdocuments?: {\n\t\t\tgetCurrent?: () => {\n\t\t\t\thistory?: {\n\t\t\t\t\taddItem: AddHistoryItem;\n\t\t\t\t};\n\t\t\t};\n\t\t};\n\t};\n};\n\nconst HistoryManagerNotAvailable = createError( {\n\tcode: 'history_manager_not_available',\n\tmessage: 'Cannot access History manager.',\n} );\n\nexport function getHistoryManager() {\n\tconst extendedWindow = window as unknown as WindowWithHistoryManager;\n\n\tconst historyManger = extendedWindow.elementor?.documents?.getCurrent?.()?.history;\n\n\tif ( ! historyManger ) {\n\t\tthrow new HistoryManagerNotAvailable();\n\t}\n\n\treturn historyManger;\n}\n","export type WindowWithDataHooks = Window & {\n\t$e: {\n\t\tmodules?: {\n\t\t\thookData?: {\n\t\t\t\t[ K in keyof HooksMap as Capitalize< K > ]: HooksMap[ K ];\n\t\t\t};\n\t\t};\n\t};\n};\n\ntype HooksMap = Record< HookType, typeof DataHook | undefined >;\n\ntype HookType = 'after' | 'dependency';\n\nexport type Args = Record< string, unknown >;\n\nexport declare class DataHook {\n\tgetCommand(): string;\n\tgetId(): string;\n\tapply( args: Args ): unknown;\n\tregister(): void;\n}\n\nlet hookId = 0;\n\nexport function registerDataHook( type: 'dependency', command: string, callback: ( args: Args ) => boolean ): DataHook;\n\nexport function registerDataHook(\n\ttype: 'after',\n\tcommand: string,\n\tcallback: ( args: Args ) => void | Promise< void >\n): DataHook;\n\nexport function registerDataHook( type: HookType, command: string, callback: ( args: Args ) => unknown ): DataHook {\n\tconst eWindow = window as unknown as WindowWithDataHooks;\n\tconst hooksClasses = eWindow.$e?.modules?.hookData;\n\n\tconst hooksMap = {\n\t\tafter: hooksClasses?.After,\n\t\tdependency: hooksClasses?.Dependency,\n\t} satisfies HooksMap;\n\n\tconst HookClass = hooksMap[ type ];\n\n\tif ( ! HookClass ) {\n\t\tthrow new Error( `Data hook '${ type }' is not available` );\n\t}\n\n\tconst currentHookId = ++hookId;\n\n\tconst hook = new ( class extends HookClass {\n\t\tgetCommand() {\n\t\t\treturn command;\n\t\t}\n\n\t\tgetId() {\n\t\t\treturn `${ command }--data--${ currentHookId }`;\n\t\t}\n\n\t\tapply( args: Args ) {\n\t\t\treturn callback( args );\n\t\t}\n\t} )();\n\n\thook.register();\n\n\treturn hook;\n}\n","import { type Args, registerDataHook } from './register-data-hook';\n\ntype BlockCommandArgs = {\n\tcommand: string;\n\tcondition: ( args: Args ) => boolean;\n};\n\nexport function blockCommand( { command, condition }: BlockCommandArgs ) {\n\treturn registerDataHook( 'dependency', command, ( args ) => {\n\t\tconst shouldBlock = condition( args );\n\n\t\t// Should return `false` to prevent the command from running.\n\t\treturn ! shouldBlock;\n\t} );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEO,SAAS,iBAAuB,OAA+C;AAIrF,SACC,CAAC,CAAE,SACH,aAAa,OAAO,SACpB,OAAO,OAAQ,OAAO,SAAU,KAChC,OAAO,OAAQ,OAAO,MAAO,KAC7B,OAAO,OAAQ,OAAO,MAAO;AAE/B;AAEO,SAAS,wBAA8B,UAA8C;AAC3F,SAAO,IAAI,QAAS,CAAE,SAAS,WAAY;AAC1C,aAAS,KAAM,SAAS,MAAO;AAAA,EAChC,CAAE;AACH;;;ACZA,eAAsB,WAAY,SAAiB,MAAe,EAAE,WAAW,MAAM,IAAuB,CAA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AAgB,EAAE;AAExB,QAAM,OAAO,IAAM,cAAc,UAAU;AAAA,IAC1C,aAAa;AACZ,aAAO;AAAA,IACR;AAAA,IAEA,QAAQ;AACP,aAAO,GAAI,OAAQ,WAAY,aAAc;AAAA,IAC9C;AAAA,IAEA,MAAO,MAAa;AACnB,aAAO,SAAU,IAAK;AAAA,IACvB;AAAA,EACD,EAAI;AAEJ,OAAK,SAAS;AAEd,SAAO;AACR;;;AC5DO,SAAS,aAAc,EAAE,SAAS,UAAU,GAAsB;AACxE,SAAO,iBAAkB,cAAc,SAAS,CAAE,SAAU;AAC3D,UAAM,cAAc,UAAW,IAAK;AAGpC,WAAO,CAAE;AAAA,EACV,CAAE;AACH;","names":["isRouteActive","import_utils","import_utils"]}
|
package/dist/index.mjs
CHANGED
|
@@ -218,6 +218,11 @@ function makeEventHandler(event) {
|
|
|
218
218
|
}
|
|
219
219
|
|
|
220
220
|
// src/readers/index.ts
|
|
221
|
+
var EXPERIMENTAL_FEATURES = {
|
|
222
|
+
CUSTOM_CSS: "atomic_custom_css",
|
|
223
|
+
TRANSITIONS: "atomic_widgets_should_use_transition",
|
|
224
|
+
UNSTABLE_REPEATER: "e_unstable_repeater"
|
|
225
|
+
};
|
|
221
226
|
function isRouteActive(route) {
|
|
222
227
|
const extendedWindow = window;
|
|
223
228
|
return !!extendedWindow.$e?.routes?.isPartOf(route);
|
|
@@ -274,6 +279,9 @@ function useRouteStatus(route, { blockOnKitRoutes = true, allowedEditModes = ["e
|
|
|
274
279
|
};
|
|
275
280
|
}
|
|
276
281
|
|
|
282
|
+
// src/undoable/undoable.ts
|
|
283
|
+
import { debounce } from "@elementor/utils";
|
|
284
|
+
|
|
277
285
|
// src/undoable/get-history-manager.ts
|
|
278
286
|
import { createError } from "@elementor/utils";
|
|
279
287
|
var HistoryManagerNotAvailable = createError({
|
|
@@ -292,12 +300,12 @@ function getHistoryManager() {
|
|
|
292
300
|
// src/undoable/undoable.ts
|
|
293
301
|
function undoable(actions, options) {
|
|
294
302
|
actions.redo ??= actions.do;
|
|
303
|
+
const _addHistoryItem = options.debounce ? debounce(addHistoryItem, options.debounce.wait) : addHistoryItem;
|
|
295
304
|
return (payload) => {
|
|
296
305
|
const _payload = payload;
|
|
297
306
|
const _actions = actions;
|
|
298
|
-
const history = getHistoryManager();
|
|
299
307
|
let result = _actions.do(_payload);
|
|
300
|
-
|
|
308
|
+
_addHistoryItem({
|
|
301
309
|
title: normalizeToGenerator(options.title)(_payload, result),
|
|
302
310
|
subTitle: normalizeToGenerator(options.subtitle)(_payload, result),
|
|
303
311
|
type: "",
|
|
@@ -315,6 +323,10 @@ function undoable(actions, options) {
|
|
|
315
323
|
function normalizeToGenerator(value) {
|
|
316
324
|
return typeof value === "function" ? value : () => value ?? "";
|
|
317
325
|
}
|
|
326
|
+
function addHistoryItem(item) {
|
|
327
|
+
const history = getHistoryManager();
|
|
328
|
+
history.addItem(item);
|
|
329
|
+
}
|
|
318
330
|
|
|
319
331
|
// src/data-hooks/register-data-hook.ts
|
|
320
332
|
var hookId = 0;
|
|
@@ -353,6 +365,7 @@ function blockCommand({ command, condition }) {
|
|
|
353
365
|
});
|
|
354
366
|
}
|
|
355
367
|
export {
|
|
368
|
+
EXPERIMENTAL_FEATURES,
|
|
356
369
|
dispatchReadyEvent as __privateDispatchReadyEvent,
|
|
357
370
|
flushListeners as __privateFlushListeners,
|
|
358
371
|
isRouteActive as __privateIsRouteActive,
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/dispatchers/utils.ts","../src/dispatchers/dispatchers.ts","../src/listeners/event-creators.ts","../src/listeners/is-ready.ts","../src/listeners/utils.ts","../src/listeners/listeners.ts","../src/readers/index.ts","../src/hooks/use-listen-to.ts","../src/hooks/use-is-route-active.ts","../src/edit-mode.ts","../src/hooks/use-route-status.ts","../src/undoable/get-history-manager.ts","../src/undoable/undoable.ts","../src/data-hooks/register-data-hook.ts","../src/data-hooks/block-command.ts"],"sourcesContent":["import { type jQueryDeferred } from './types';\n\nexport function isJQueryDeferred< T >( value: unknown ): value is jQueryDeferred< T > {\n\t// TODO: Copied from:\n\t// https://github.com/elementor/elementor/blob/6a74fc9/modules/web-cli/assets/js/core/commands.js#L410\n\n\treturn (\n\t\t!! value &&\n\t\t'object' === typeof value &&\n\t\tObject.hasOwn( value, 'promise' ) &&\n\t\tObject.hasOwn( value, 'then' ) &&\n\t\tObject.hasOwn( value, 'fail' )\n\t);\n}\n\nexport function promisifyJQueryDeferred< T >( deferred: jQueryDeferred< T > ): Promise< T > {\n\treturn new Promise( ( resolve, reject ) => {\n\t\tdeferred.then( resolve, reject );\n\t} );\n}\n","import { type ExtendedWindow } from './types';\nimport { isJQueryDeferred, promisifyJQueryDeferred } from './utils';\n\ntype RunCommandOptions = {\n\tinternal?: boolean;\n};\n\nexport async function runCommand( command: string, args?: object, { internal = false }: RunCommandOptions = {} ) {\n\tconst result = runCommandSync( command, args, { internal } );\n\n\tif ( result instanceof Promise ) {\n\t\treturn result;\n\t}\n\n\tif ( isJQueryDeferred( result ) ) {\n\t\treturn promisifyJQueryDeferred( result );\n\t}\n\n\treturn Promise.resolve( result );\n}\n\nexport function runCommandSync( command: string, args?: object, { internal = false }: RunCommandOptions = {} ) {\n\tconst extendedWindow = window as unknown as ExtendedWindow;\n\n\tconst run = internal ? extendedWindow.$e?.internal : extendedWindow.$e?.run;\n\n\tif ( ! run ) {\n\t\tconst runnerName = internal ? '$e.internal' : '$e.run';\n\n\t\tthrow new Error( `\\`${ runnerName }()\\` is not available` );\n\t}\n\n\treturn run( command, args );\n}\n\nexport function openRoute( route: string ) {\n\tconst extendedWindow = window as unknown as ExtendedWindow;\n\n\tif ( ! extendedWindow.$e?.route ) {\n\t\treturn Promise.reject( '`$e.route()` is not available' );\n\t}\n\n\ttry {\n\t\treturn Promise.resolve( extendedWindow.$e.route( route ) );\n\t} catch ( e ) {\n\t\treturn Promise.reject( e );\n\t}\n}\n\nexport function registerRoute( route: string ) {\n\tconst extendedWindow = window as unknown as ExtendedWindow;\n\n\tif ( ! extendedWindow.$e?.routes?.register ) {\n\t\treturn Promise.reject( '`$e.routes.register()` is not available' );\n\t}\n\n\tconst routeParts = route.split( '/' );\n\n\tif ( routeParts.length < 2 ) {\n\t\treturn Promise.reject( `\\`${ route }\\` is an invalid route` );\n\t}\n\n\tconst componentRoute = routeParts.pop() as string; // routeParts.length must be >= 2\n\tconst component = routeParts.join( '/' );\n\n\ttry {\n\t\treturn Promise.resolve( extendedWindow.$e.routes.register( component, componentRoute, () => null ) );\n\t} catch ( e ) {\n\t\treturn Promise.reject( e );\n\t}\n}\n","import { type CommandEventDescriptor, type RouteEventDescriptor, type WindowEventDescriptor } from './types';\n\nexport const commandStartEvent = ( command: CommandEventDescriptor[ 'name' ] ): CommandEventDescriptor => {\n\treturn {\n\t\ttype: 'command',\n\t\tname: command,\n\t\tstate: 'before',\n\t};\n};\n\nexport const commandEndEvent = ( command: CommandEventDescriptor[ 'name' ] ): CommandEventDescriptor => {\n\treturn {\n\t\ttype: 'command',\n\t\tname: command,\n\t\tstate: 'after',\n\t};\n};\n\nexport const routeOpenEvent = ( route: RouteEventDescriptor[ 'name' ] ): RouteEventDescriptor => {\n\treturn {\n\t\ttype: 'route',\n\t\tname: route,\n\t\tstate: 'open',\n\t};\n};\n\nexport const routeCloseEvent = ( route: RouteEventDescriptor[ 'name' ] ): RouteEventDescriptor => {\n\treturn {\n\t\ttype: 'route',\n\t\tname: route,\n\t\tstate: 'close',\n\t};\n};\n\nexport const windowEvent = ( event: WindowEventDescriptor[ 'name' ] ): WindowEventDescriptor => {\n\treturn {\n\t\ttype: 'window-event',\n\t\tname: event,\n\t};\n};\n\nexport const v1ReadyEvent = () => {\n\treturn windowEvent( 'elementor/initialized' );\n};\n","/**\n * This file is used to store the state of the isReady variable, which is used to determine\n * if the adapter is ready to receive events (editor v1 and v2 are loaded).\n */\n\nlet ready = false;\n\nexport function isReady() {\n\treturn ready;\n}\n\nexport function setReady( value: boolean ) {\n\tready = value;\n}\n","import { setReady } from './is-ready';\nimport { type ExtendedWindow, type ListenerEvent } from './types';\n\nexport function dispatchReadyEvent() {\n\treturn getV1LoadingPromise().then( () => {\n\t\tsetReady( true );\n\t\twindow.dispatchEvent( new CustomEvent( 'elementor/initialized' ) );\n\t} );\n}\n\nfunction getV1LoadingPromise() {\n\tconst v1LoadingPromise = ( window as unknown as ExtendedWindow ).__elementorEditorV1LoadingPromise;\n\n\tif ( ! v1LoadingPromise ) {\n\t\treturn Promise.reject( 'Elementor Editor V1 is not loaded' );\n\t}\n\n\treturn v1LoadingPromise;\n}\n\nexport function normalizeEvent( e: ListenerEvent[ 'originalEvent' ] ): ListenerEvent {\n\tif ( e instanceof CustomEvent && e.detail?.command ) {\n\t\treturn {\n\t\t\ttype: 'command',\n\t\t\tcommand: e.detail.command,\n\t\t\targs: e.detail.args,\n\t\t\toriginalEvent: e,\n\t\t};\n\t}\n\n\tif ( e instanceof CustomEvent && e.detail?.route ) {\n\t\treturn {\n\t\t\ttype: 'route',\n\t\t\troute: e.detail.route,\n\t\t\toriginalEvent: e,\n\t\t};\n\t}\n\n\treturn {\n\t\ttype: 'window-event',\n\t\tevent: e.type,\n\t\toriginalEvent: e,\n\t};\n}\n","import { isReady, setReady } from './is-ready';\nimport {\n\ttype CommandEventDescriptor,\n\ttype EventDescriptor,\n\ttype ListenerCallback,\n\ttype RouteEventDescriptor,\n\ttype WindowEventDescriptor,\n} from './types';\nimport { normalizeEvent } from './utils';\n\nconst callbacksByEvent = new Map< EventDescriptor[ 'name' ], ListenerCallback[] >();\nlet abortController = new AbortController();\n\nexport function listenTo( eventDescriptors: EventDescriptor | EventDescriptor[], callback: ListenerCallback ) {\n\tif ( ! Array.isArray( eventDescriptors ) ) {\n\t\teventDescriptors = [ eventDescriptors ];\n\t}\n\n\t// @see https://github.com/typescript-eslint/typescript-eslint/issues/2841\n\t// eslint-disable-next-line array-callback-return -- Clashes with typescript.\n\tconst cleanups = eventDescriptors.map( ( event ) => {\n\t\tconst { type, name } = event;\n\n\t\tswitch ( type ) {\n\t\t\tcase 'command':\n\t\t\t\treturn registerCommandListener( name, event.state, callback );\n\n\t\t\tcase 'route':\n\t\t\t\treturn registerRouteListener( name, event.state, callback );\n\n\t\t\tcase 'window-event':\n\t\t\t\treturn registerWindowEventListener( name, callback );\n\t\t}\n\t} );\n\n\treturn () => {\n\t\tcleanups.forEach( ( cleanup ) => cleanup() );\n\t};\n}\n\nexport function flushListeners() {\n\tabortController.abort();\n\tcallbacksByEvent.clear();\n\tsetReady( false );\n\n\tabortController = new AbortController();\n}\n\nfunction registerCommandListener(\n\tcommand: CommandEventDescriptor[ 'name' ],\n\tstate: CommandEventDescriptor[ 'state' ],\n\tcallback: ListenerCallback\n) {\n\treturn registerWindowEventListener( `elementor/commands/run/${ state }`, ( e ) => {\n\t\tconst shouldRunCallback = e.type === 'command' && e.command === command;\n\n\t\tif ( shouldRunCallback ) {\n\t\t\tcallback( e );\n\t\t}\n\t} );\n}\n\nfunction registerRouteListener(\n\troute: RouteEventDescriptor[ 'name' ],\n\tstate: RouteEventDescriptor[ 'state' ],\n\tcallback: ListenerCallback\n) {\n\treturn registerWindowEventListener( `elementor/routes/${ state }`, ( e ) => {\n\t\tconst shouldRunCallback = e.type === 'route' && e.route.startsWith( route );\n\n\t\tif ( shouldRunCallback ) {\n\t\t\tcallback( e );\n\t\t}\n\t} );\n}\n\nfunction registerWindowEventListener( event: WindowEventDescriptor[ 'name' ], callback: ListenerCallback ) {\n\tconst isFirstListener = ! callbacksByEvent.has( event );\n\n\tif ( isFirstListener ) {\n\t\tcallbacksByEvent.set( event, [] );\n\n\t\taddListener( event );\n\t}\n\n\tcallbacksByEvent.get( event )?.push( callback );\n\n\treturn () => {\n\t\tconst callbacks = callbacksByEvent.get( event );\n\n\t\tif ( ! callbacks?.length ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst filtered = callbacks.filter( ( cb ) => cb !== callback );\n\n\t\tcallbacksByEvent.set( event, filtered );\n\t};\n}\n\nfunction addListener( event: EventDescriptor[ 'name' ] ) {\n\twindow.addEventListener( event, makeEventHandler( event ), { signal: abortController.signal } );\n}\n\nfunction makeEventHandler( event: EventDescriptor[ 'name' ] ): EventListener {\n\treturn ( e ) => {\n\t\tif ( ! isReady() ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst normalizedEvent = normalizeEvent( e );\n\n\t\tcallbacksByEvent.get( event )?.forEach( ( callback ) => {\n\t\t\tcallback( normalizedEvent );\n\t\t} );\n\t};\n}\n","import { type ExtendedWindow } from './types';\n\nexport function isRouteActive( route: string ) {\n\tconst extendedWindow = window as unknown as ExtendedWindow;\n\n\treturn !! extendedWindow.$e?.routes?.isPartOf( route );\n}\n\nexport const isExperimentActive = ( experiment: string ) => {\n\tconst extendedWindow = window as unknown as ExtendedWindow;\n\n\treturn !! extendedWindow.elementorCommon?.config?.experimentalFeatures?.[ experiment ];\n};\n","import { useEffect, useState } from 'react';\n\nimport { type EventDescriptor, listenTo } from '../listeners';\n\nexport default function useListenTo< T >(\n\tevent: EventDescriptor | EventDescriptor[],\n\tgetSnapshot: () => T,\n\tdeps: unknown[] = []\n) {\n\tconst [ snapshot, setSnapshot ] = useState( () => getSnapshot() );\n\n\tuseEffect( () => {\n\t\tconst updateState = () => setSnapshot( getSnapshot() );\n\n\t\t// Ensure the state is re-calculated when the dependencies have been changed.\n\t\tupdateState();\n\n\t\treturn listenTo( event, updateState );\n\t}, deps ); // eslint-disable-line react-hooks/exhaustive-deps\n\n\treturn snapshot;\n}\n","import { routeCloseEvent, type RouteEventDescriptor, routeOpenEvent } from '../listeners';\nimport { isRouteActive } from '../readers';\nimport useListenTo from './use-listen-to';\n\nexport default function useIsRouteActive( route: RouteEventDescriptor[ 'name' ] ) {\n\treturn useListenTo( [ routeOpenEvent( route ), routeCloseEvent( route ) ], () => isRouteActive( route ), [\n\t\troute,\n\t] );\n}\n","import useListenTo from './hooks/use-listen-to';\nimport { windowEvent } from './listeners';\n\nexport type EditMode = 'edit' | 'preview' | 'picker' | ( string & {} );\n\nexport type ExtendedWindow = Window & {\n\telementor: {\n\t\tchangeEditMode: ( newMode: EditMode ) => void;\n\t\tchannels: {\n\t\t\tdataEditMode: {\n\t\t\t\trequest: ( key: 'activeMode' ) => EditMode;\n\t\t\t};\n\t\t};\n\t};\n};\n\nexport function useEditMode() {\n\treturn useListenTo( windowEvent( 'elementor/edit-mode/change' ), getCurrentEditMode );\n}\n\nfunction getCurrentEditMode() {\n\tconst extendedWindow = window as unknown as ExtendedWindow;\n\n\treturn extendedWindow.elementor.channels.dataEditMode.request( 'activeMode' );\n}\n\nexport function changeEditMode( newMode: EditMode ) {\n\tconst extendedWindow = window as unknown as ExtendedWindow;\n\n\treturn extendedWindow.elementor.changeEditMode( newMode );\n}\n","import { type EditMode, useEditMode } from '../edit-mode';\nimport { type RouteEventDescriptor } from '../listeners';\nimport useIsRouteActive from './use-is-route-active';\n\nexport type UseRouteStatusOptions = {\n\tblockOnKitRoutes?: boolean;\n\tallowedEditModes?: EditMode[];\n};\n\nexport default function useRouteStatus(\n\troute: RouteEventDescriptor[ 'name' ],\n\t{ blockOnKitRoutes = true, allowedEditModes = [ 'edit' ] }: UseRouteStatusOptions = {}\n) {\n\tconst isRouteActive = useIsRouteActive( route );\n\tconst isKitRouteActive = useIsRouteActive( 'panel/global' );\n\tconst currentEditMode = useEditMode();\n\n\tconst isBlockedByEditMode = ! allowedEditModes.includes( currentEditMode );\n\n\tconst isBlockedByKit = blockOnKitRoutes && isKitRouteActive;\n\n\tconst isActive = isRouteActive && ! isBlockedByEditMode;\n\n\tconst isBlocked = isBlockedByEditMode || isBlockedByKit;\n\n\treturn {\n\t\tisActive,\n\t\tisBlocked,\n\t};\n}\n","import { createError } from '@elementor/utils';\n\nexport type HistoryItem = {\n\ttitle: string;\n\tsubTitle: string;\n\ttype: string;\n\trestore: ( item: HistoryItem, isRedo: boolean ) => void;\n};\n\ntype AddHistoryItem = ( item: HistoryItem ) => void;\n\nexport type WindowWithHistoryManager = Window & {\n\telementor?: {\n\t\tdocuments?: {\n\t\t\tgetCurrent?: () => {\n\t\t\t\thistory?: {\n\t\t\t\t\taddItem: AddHistoryItem;\n\t\t\t\t};\n\t\t\t};\n\t\t};\n\t};\n};\n\nconst HistoryManagerNotAvailable = createError( {\n\tcode: 'history_manager_not_available',\n\tmessage: 'Cannot access History manager.',\n} );\n\nexport function getHistoryManager() {\n\tconst extendedWindow = window as unknown as WindowWithHistoryManager;\n\n\tconst historyManger = extendedWindow.elementor?.documents?.getCurrent?.()?.history;\n\n\tif ( ! historyManger ) {\n\t\tthrow new HistoryManagerNotAvailable();\n\t}\n\n\treturn historyManger;\n}\n","import { getHistoryManager } from './get-history-manager';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Payload = Record< string, any > | undefined;\n\ntype LabelGenerator< TPayload extends Payload, TDoReturn > = ( payload: TPayload, doReturn: TDoReturn ) => string;\n\ntype Actions< TPayload extends Payload, TDoReturn, TUndoReturn > = {\n\tdo: ( payload: TPayload ) => Awaited< TDoReturn >;\n\tundo: ( payload: TPayload, doReturn: Awaited< TDoReturn > ) => Awaited< TUndoReturn >;\n\tredo?: ( payload: TPayload, doReturn: Awaited< TDoReturn > ) => Awaited< TDoReturn >;\n};\n\ntype Options< TPayload extends Payload, TDoReturn > = {\n\ttitle: string | LabelGenerator< TPayload, TDoReturn >;\n\tsubtitle?: string | LabelGenerator< TPayload, TDoReturn >;\n};\n\n// Action WITHOUT a payload.\nexport function undoable< TDoReturn, TUndoReturn >(\n\tactions: Actions< undefined, TDoReturn, TUndoReturn >,\n\toptions: Options< undefined, NoInfer< TDoReturn > >\n): () => TDoReturn;\n\n// Action WITH a payload.\nexport function undoable< TPayload extends NonNullable< Payload >, TDoReturn, TUndoReturn >(\n\tactions: Actions< TPayload, TDoReturn, TUndoReturn >,\n\toptions: Options< TPayload, NoInfer< TDoReturn > >\n): ( payload: TPayload ) => TDoReturn;\n\nexport function undoable< TPayload extends Payload, TDoReturn, TUndoReturn >(\n\tactions: Actions< TPayload, TDoReturn, TUndoReturn >,\n\toptions: Options< TPayload, NoInfer< TDoReturn > >\n): ( payload?: Payload ) => TDoReturn {\n\tactions.redo ??= actions.do;\n\n\treturn ( payload ) => {\n\t\tconst _payload = payload as TPayload;\n\t\tconst _actions = actions as Required< Actions< TPayload, TDoReturn, TUndoReturn > >;\n\n\t\tconst history = getHistoryManager();\n\n\t\tlet result = _actions.do( _payload );\n\n\t\thistory.addItem( {\n\t\t\ttitle: normalizeToGenerator( options.title )( _payload, result ),\n\t\t\tsubTitle: normalizeToGenerator( options.subtitle )( _payload, result ),\n\t\t\ttype: '',\n\t\t\trestore: ( _, isRedo ) => {\n\t\t\t\tif ( isRedo ) {\n\t\t\t\t\tresult = _actions.redo( _payload, result );\n\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t_actions.undo( _payload, result );\n\t\t\t},\n\t\t} );\n\n\t\treturn result;\n\t};\n}\n\nfunction normalizeToGenerator< TPayload extends Payload, TDoReturn >(\n\tvalue: string | undefined | LabelGenerator< TPayload, TDoReturn >\n) {\n\treturn typeof value === 'function' ? value : () => value ?? '';\n}\n","export type WindowWithDataHooks = Window & {\n\t$e: {\n\t\tmodules?: {\n\t\t\thookData?: {\n\t\t\t\t[ K in keyof HooksMap as Capitalize< K > ]: HooksMap[ K ];\n\t\t\t};\n\t\t};\n\t};\n};\n\ntype HooksMap = Record< HookType, typeof DataHook | undefined >;\n\ntype HookType = 'after' | 'dependency';\n\nexport type Args = Record< string, unknown >;\n\nexport declare class DataHook {\n\tgetCommand(): string;\n\tgetId(): string;\n\tapply( args: Args ): unknown;\n\tregister(): void;\n}\n\nlet hookId = 0;\n\nexport function registerDataHook( type: 'dependency', command: string, callback: ( args: Args ) => boolean ): DataHook;\n\nexport function registerDataHook(\n\ttype: 'after',\n\tcommand: string,\n\tcallback: ( args: Args ) => void | Promise< void >\n): DataHook;\n\nexport function registerDataHook( type: HookType, command: string, callback: ( args: Args ) => unknown ): DataHook {\n\tconst eWindow = window as unknown as WindowWithDataHooks;\n\tconst hooksClasses = eWindow.$e?.modules?.hookData;\n\n\tconst hooksMap = {\n\t\tafter: hooksClasses?.After,\n\t\tdependency: hooksClasses?.Dependency,\n\t} satisfies HooksMap;\n\n\tconst HookClass = hooksMap[ type ];\n\n\tif ( ! HookClass ) {\n\t\tthrow new Error( `Data hook '${ type }' is not available` );\n\t}\n\n\tconst currentHookId = ++hookId;\n\n\tconst hook = new ( class extends HookClass {\n\t\tgetCommand() {\n\t\t\treturn command;\n\t\t}\n\n\t\tgetId() {\n\t\t\treturn `${ command }--data--${ currentHookId }`;\n\t\t}\n\n\t\tapply( args: Args ) {\n\t\t\treturn callback( args );\n\t\t}\n\t} )();\n\n\thook.register();\n\n\treturn hook;\n}\n","import { type Args, registerDataHook } from './register-data-hook';\n\ntype BlockCommandArgs = {\n\tcommand: string;\n\tcondition: ( args: Args ) => boolean;\n};\n\nexport function blockCommand( { command, condition }: BlockCommandArgs ) {\n\treturn registerDataHook( 'dependency', command, ( args ) => {\n\t\tconst shouldBlock = condition( args );\n\n\t\t// Should return `false` to prevent the command from running.\n\t\treturn ! shouldBlock;\n\t} );\n}\n"],"mappings":";AAEO,SAAS,iBAAuB,OAA+C;AAIrF,SACC,CAAC,CAAE,SACH,aAAa,OAAO,SACpB,OAAO,OAAQ,OAAO,SAAU,KAChC,OAAO,OAAQ,OAAO,MAAO,KAC7B,OAAO,OAAQ,OAAO,MAAO;AAE/B;AAEO,SAAS,wBAA8B,UAA8C;AAC3F,SAAO,IAAI,QAAS,CAAE,SAAS,WAAY;AAC1C,aAAS,KAAM,SAAS,MAAO;AAAA,EAChC,CAAE;AACH;;;ACZA,eAAsB,WAAY,SAAiB,MAAe,EAAE,WAAW,MAAM,IAAuB,CAAC,GAAI;AAChH,QAAM,SAAS,eAAgB,SAAS,MAAM,EAAE,SAAS,CAAE;AAE3D,MAAK,kBAAkB,SAAU;AAChC,WAAO;AA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AkB,cAAc,SAAS,CAAE,SAAU;AAC3D,UAAM,cAAc,UAAW,IAAK;AAGpC,WAAO,CAAE;AAAA,EACV,CAAE;AACH;","names":["isRouteActive"]}
|
|
1
|
+
{"version":3,"sources":["../src/dispatchers/utils.ts","../src/dispatchers/dispatchers.ts","../src/listeners/event-creators.ts","../src/listeners/is-ready.ts","../src/listeners/utils.ts","../src/listeners/listeners.ts","../src/readers/index.ts","../src/hooks/use-listen-to.ts","../src/hooks/use-is-route-active.ts","../src/edit-mode.ts","../src/hooks/use-route-status.ts","../src/undoable/undoable.ts","../src/undoable/get-history-manager.ts","../src/data-hooks/register-data-hook.ts","../src/data-hooks/block-command.ts"],"sourcesContent":["import { type jQueryDeferred } from './types';\n\nexport function isJQueryDeferred< T >( value: unknown ): value is jQueryDeferred< T > {\n\t// TODO: Copied from:\n\t// https://github.com/elementor/elementor/blob/6a74fc9/modules/web-cli/assets/js/core/commands.js#L410\n\n\treturn (\n\t\t!! value &&\n\t\t'object' === typeof value &&\n\t\tObject.hasOwn( value, 'promise' ) &&\n\t\tObject.hasOwn( value, 'then' ) &&\n\t\tObject.hasOwn( value, 'fail' )\n\t);\n}\n\nexport function promisifyJQueryDeferred< T >( deferred: jQueryDeferred< T > ): Promise< T > {\n\treturn new Promise( ( resolve, reject ) => {\n\t\tdeferred.then( resolve, reject );\n\t} );\n}\n","import { type ExtendedWindow } from './types';\nimport { isJQueryDeferred, promisifyJQueryDeferred } from './utils';\n\ntype RunCommandOptions = {\n\tinternal?: boolean;\n};\n\nexport async function runCommand( command: string, args?: object, { internal = false }: RunCommandOptions = {} ) {\n\tconst result = runCommandSync( command, args, { internal } );\n\n\tif ( result instanceof Promise ) {\n\t\treturn result;\n\t}\n\n\tif ( isJQueryDeferred( result ) ) {\n\t\treturn promisifyJQueryDeferred( result );\n\t}\n\n\treturn Promise.resolve( result );\n}\n\nexport function runCommandSync( command: string, args?: object, { internal = false }: RunCommandOptions = {} ) {\n\tconst extendedWindow = window as unknown as ExtendedWindow;\n\n\tconst run = internal ? extendedWindow.$e?.internal : extendedWindow.$e?.run;\n\n\tif ( ! run ) {\n\t\tconst runnerName = internal ? '$e.internal' : '$e.run';\n\n\t\tthrow new Error( `\\`${ runnerName }()\\` is not available` );\n\t}\n\n\treturn run( command, args );\n}\n\nexport function openRoute( route: string ) {\n\tconst extendedWindow = window as unknown as ExtendedWindow;\n\n\tif ( ! extendedWindow.$e?.route ) {\n\t\treturn Promise.reject( '`$e.route()` is not available' );\n\t}\n\n\ttry {\n\t\treturn Promise.resolve( extendedWindow.$e.route( route ) );\n\t} catch ( e ) {\n\t\treturn Promise.reject( e );\n\t}\n}\n\nexport function registerRoute( route: string ) {\n\tconst extendedWindow = window as unknown as ExtendedWindow;\n\n\tif ( ! extendedWindow.$e?.routes?.register ) {\n\t\treturn Promise.reject( '`$e.routes.register()` is not available' );\n\t}\n\n\tconst routeParts = route.split( '/' );\n\n\tif ( routeParts.length < 2 ) {\n\t\treturn Promise.reject( `\\`${ route }\\` is an invalid route` );\n\t}\n\n\tconst componentRoute = routeParts.pop() as string; // routeParts.length must be >= 2\n\tconst component = routeParts.join( '/' );\n\n\ttry {\n\t\treturn Promise.resolve( extendedWindow.$e.routes.register( component, componentRoute, () => null ) );\n\t} catch ( e ) {\n\t\treturn Promise.reject( e );\n\t}\n}\n","import { type CommandEventDescriptor, type RouteEventDescriptor, type WindowEventDescriptor } from './types';\n\nexport const commandStartEvent = ( command: CommandEventDescriptor[ 'name' ] ): CommandEventDescriptor => {\n\treturn {\n\t\ttype: 'command',\n\t\tname: command,\n\t\tstate: 'before',\n\t};\n};\n\nexport const commandEndEvent = ( command: CommandEventDescriptor[ 'name' ] ): CommandEventDescriptor => {\n\treturn {\n\t\ttype: 'command',\n\t\tname: command,\n\t\tstate: 'after',\n\t};\n};\n\nexport const routeOpenEvent = ( route: RouteEventDescriptor[ 'name' ] ): RouteEventDescriptor => {\n\treturn {\n\t\ttype: 'route',\n\t\tname: route,\n\t\tstate: 'open',\n\t};\n};\n\nexport const routeCloseEvent = ( route: RouteEventDescriptor[ 'name' ] ): RouteEventDescriptor => {\n\treturn {\n\t\ttype: 'route',\n\t\tname: route,\n\t\tstate: 'close',\n\t};\n};\n\nexport const windowEvent = ( event: WindowEventDescriptor[ 'name' ] ): WindowEventDescriptor => {\n\treturn {\n\t\ttype: 'window-event',\n\t\tname: event,\n\t};\n};\n\nexport const v1ReadyEvent = () => {\n\treturn windowEvent( 'elementor/initialized' );\n};\n","/**\n * This file is used to store the state of the isReady variable, which is used to determine\n * if the adapter is ready to receive events (editor v1 and v2 are loaded).\n */\n\nlet ready = false;\n\nexport function isReady() {\n\treturn ready;\n}\n\nexport function setReady( value: boolean ) {\n\tready = value;\n}\n","import { setReady } from './is-ready';\nimport { type ExtendedWindow, type ListenerEvent } from './types';\n\nexport function dispatchReadyEvent() {\n\treturn getV1LoadingPromise().then( () => {\n\t\tsetReady( true );\n\t\twindow.dispatchEvent( new CustomEvent( 'elementor/initialized' ) );\n\t} );\n}\n\nfunction getV1LoadingPromise() {\n\tconst v1LoadingPromise = ( window as unknown as ExtendedWindow ).__elementorEditorV1LoadingPromise;\n\n\tif ( ! v1LoadingPromise ) {\n\t\treturn Promise.reject( 'Elementor Editor V1 is not loaded' );\n\t}\n\n\treturn v1LoadingPromise;\n}\n\nexport function normalizeEvent( e: ListenerEvent[ 'originalEvent' ] ): ListenerEvent {\n\tif ( e instanceof CustomEvent && e.detail?.command ) {\n\t\treturn {\n\t\t\ttype: 'command',\n\t\t\tcommand: e.detail.command,\n\t\t\targs: e.detail.args,\n\t\t\toriginalEvent: e,\n\t\t};\n\t}\n\n\tif ( e instanceof CustomEvent && e.detail?.route ) {\n\t\treturn {\n\t\t\ttype: 'route',\n\t\t\troute: e.detail.route,\n\t\t\toriginalEvent: e,\n\t\t};\n\t}\n\n\treturn {\n\t\ttype: 'window-event',\n\t\tevent: e.type,\n\t\toriginalEvent: e,\n\t};\n}\n","import { isReady, setReady } from './is-ready';\nimport {\n\ttype CommandEventDescriptor,\n\ttype EventDescriptor,\n\ttype ListenerCallback,\n\ttype RouteEventDescriptor,\n\ttype WindowEventDescriptor,\n} from './types';\nimport { normalizeEvent } from './utils';\n\nconst callbacksByEvent = new Map< EventDescriptor[ 'name' ], ListenerCallback[] >();\nlet abortController = new AbortController();\n\nexport function listenTo( eventDescriptors: EventDescriptor | EventDescriptor[], callback: ListenerCallback ) {\n\tif ( ! Array.isArray( eventDescriptors ) ) {\n\t\teventDescriptors = [ eventDescriptors ];\n\t}\n\n\t// @see https://github.com/typescript-eslint/typescript-eslint/issues/2841\n\t// eslint-disable-next-line array-callback-return -- Clashes with typescript.\n\tconst cleanups = eventDescriptors.map( ( event ) => {\n\t\tconst { type, name } = event;\n\n\t\tswitch ( type ) {\n\t\t\tcase 'command':\n\t\t\t\treturn registerCommandListener( name, event.state, callback );\n\n\t\t\tcase 'route':\n\t\t\t\treturn registerRouteListener( name, event.state, callback );\n\n\t\t\tcase 'window-event':\n\t\t\t\treturn registerWindowEventListener( name, callback );\n\t\t}\n\t} );\n\n\treturn () => {\n\t\tcleanups.forEach( ( cleanup ) => cleanup() );\n\t};\n}\n\nexport function flushListeners() {\n\tabortController.abort();\n\tcallbacksByEvent.clear();\n\tsetReady( false );\n\n\tabortController = new AbortController();\n}\n\nfunction registerCommandListener(\n\tcommand: CommandEventDescriptor[ 'name' ],\n\tstate: CommandEventDescriptor[ 'state' ],\n\tcallback: ListenerCallback\n) {\n\treturn registerWindowEventListener( `elementor/commands/run/${ state }`, ( e ) => {\n\t\tconst shouldRunCallback = e.type === 'command' && e.command === command;\n\n\t\tif ( shouldRunCallback ) {\n\t\t\tcallback( e );\n\t\t}\n\t} );\n}\n\nfunction registerRouteListener(\n\troute: RouteEventDescriptor[ 'name' ],\n\tstate: RouteEventDescriptor[ 'state' ],\n\tcallback: ListenerCallback\n) {\n\treturn registerWindowEventListener( `elementor/routes/${ state }`, ( e ) => {\n\t\tconst shouldRunCallback = e.type === 'route' && e.route.startsWith( route );\n\n\t\tif ( shouldRunCallback ) {\n\t\t\tcallback( e );\n\t\t}\n\t} );\n}\n\nfunction registerWindowEventListener( event: WindowEventDescriptor[ 'name' ], callback: ListenerCallback ) {\n\tconst isFirstListener = ! callbacksByEvent.has( event );\n\n\tif ( isFirstListener ) {\n\t\tcallbacksByEvent.set( event, [] );\n\n\t\taddListener( event );\n\t}\n\n\tcallbacksByEvent.get( event )?.push( callback );\n\n\treturn () => {\n\t\tconst callbacks = callbacksByEvent.get( event );\n\n\t\tif ( ! callbacks?.length ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst filtered = callbacks.filter( ( cb ) => cb !== callback );\n\n\t\tcallbacksByEvent.set( event, filtered );\n\t};\n}\n\nfunction addListener( event: EventDescriptor[ 'name' ] ) {\n\twindow.addEventListener( event, makeEventHandler( event ), { signal: abortController.signal } );\n}\n\nfunction makeEventHandler( event: EventDescriptor[ 'name' ] ): EventListener {\n\treturn ( e ) => {\n\t\tif ( ! isReady() ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst normalizedEvent = normalizeEvent( e );\n\n\t\tcallbacksByEvent.get( event )?.forEach( ( callback ) => {\n\t\t\tcallback( normalizedEvent );\n\t\t} );\n\t};\n}\n","import { type ExtendedWindow } from './types';\n\nexport const EXPERIMENTAL_FEATURES = {\n\tCUSTOM_CSS: 'atomic_custom_css',\n\tTRANSITIONS: 'atomic_widgets_should_use_transition',\n\tUNSTABLE_REPEATER: 'e_unstable_repeater',\n};\n\nexport function isRouteActive( route: string ) {\n\tconst extendedWindow = window as unknown as ExtendedWindow;\n\n\treturn !! extendedWindow.$e?.routes?.isPartOf( route );\n}\n\nexport const isExperimentActive = ( experiment: keyof typeof EXPERIMENTAL_FEATURES | string ) => {\n\tconst extendedWindow = window as unknown as ExtendedWindow;\n\n\treturn !! extendedWindow.elementorCommon?.config?.experimentalFeatures?.[ experiment ];\n};\n","import { useEffect, useState } from 'react';\n\nimport { type EventDescriptor, listenTo } from '../listeners';\n\nexport default function useListenTo< T >(\n\tevent: EventDescriptor | EventDescriptor[],\n\tgetSnapshot: () => T,\n\tdeps: unknown[] = []\n) {\n\tconst [ snapshot, setSnapshot ] = useState( () => getSnapshot() );\n\n\tuseEffect( () => {\n\t\tconst updateState = () => setSnapshot( getSnapshot() );\n\n\t\t// Ensure the state is re-calculated when the dependencies have been changed.\n\t\tupdateState();\n\n\t\treturn listenTo( event, updateState );\n\t}, deps ); // eslint-disable-line react-hooks/exhaustive-deps\n\n\treturn snapshot;\n}\n","import { routeCloseEvent, type RouteEventDescriptor, routeOpenEvent } from '../listeners';\nimport { isRouteActive } from '../readers';\nimport useListenTo from './use-listen-to';\n\nexport default function useIsRouteActive( route: RouteEventDescriptor[ 'name' ] ) {\n\treturn useListenTo( [ routeOpenEvent( route ), routeCloseEvent( route ) ], () => isRouteActive( route ), [\n\t\troute,\n\t] );\n}\n","import useListenTo from './hooks/use-listen-to';\nimport { windowEvent } from './listeners';\n\nexport type EditMode = 'edit' | 'preview' | 'picker' | ( string & {} );\n\nexport type ExtendedWindow = Window & {\n\telementor: {\n\t\tchangeEditMode: ( newMode: EditMode ) => void;\n\t\tchannels: {\n\t\t\tdataEditMode: {\n\t\t\t\trequest: ( key: 'activeMode' ) => EditMode;\n\t\t\t};\n\t\t};\n\t};\n};\n\nexport function useEditMode() {\n\treturn useListenTo( windowEvent( 'elementor/edit-mode/change' ), getCurrentEditMode );\n}\n\nfunction getCurrentEditMode() {\n\tconst extendedWindow = window as unknown as ExtendedWindow;\n\n\treturn extendedWindow.elementor.channels.dataEditMode.request( 'activeMode' );\n}\n\nexport function changeEditMode( newMode: EditMode ) {\n\tconst extendedWindow = window as unknown as ExtendedWindow;\n\n\treturn extendedWindow.elementor.changeEditMode( newMode );\n}\n","import { type EditMode, useEditMode } from '../edit-mode';\nimport { type RouteEventDescriptor } from '../listeners';\nimport useIsRouteActive from './use-is-route-active';\n\nexport type UseRouteStatusOptions = {\n\tblockOnKitRoutes?: boolean;\n\tallowedEditModes?: EditMode[];\n};\n\nexport default function useRouteStatus(\n\troute: RouteEventDescriptor[ 'name' ],\n\t{ blockOnKitRoutes = true, allowedEditModes = [ 'edit' ] }: UseRouteStatusOptions = {}\n) {\n\tconst isRouteActive = useIsRouteActive( route );\n\tconst isKitRouteActive = useIsRouteActive( 'panel/global' );\n\tconst currentEditMode = useEditMode();\n\n\tconst isBlockedByEditMode = ! allowedEditModes.includes( currentEditMode );\n\n\tconst isBlockedByKit = blockOnKitRoutes && isKitRouteActive;\n\n\tconst isActive = isRouteActive && ! isBlockedByEditMode;\n\n\tconst isBlocked = isBlockedByEditMode || isBlockedByKit;\n\n\treturn {\n\t\tisActive,\n\t\tisBlocked,\n\t};\n}\n","import { debounce } from '@elementor/utils';\n\nimport { getHistoryManager, type HistoryItem } from './get-history-manager';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Payload = Record< string, any > | undefined;\n\ntype LabelGenerator< TPayload extends Payload, TDoReturn > = ( payload: TPayload, doReturn: TDoReturn ) => string;\n\ntype Actions< TPayload extends Payload, TDoReturn, TUndoReturn > = {\n\tdo: ( payload: TPayload ) => Awaited< TDoReturn >;\n\tundo: ( payload: TPayload, doReturn: Awaited< TDoReturn > ) => Awaited< TUndoReturn >;\n\tredo?: ( payload: TPayload, doReturn: Awaited< TDoReturn > ) => Awaited< TDoReturn >;\n};\n\ntype Options< TPayload extends Payload, TDoReturn > = {\n\ttitle: string | LabelGenerator< TPayload, TDoReturn >;\n\tsubtitle?: string | LabelGenerator< TPayload, TDoReturn >;\n\tdebounce?: { wait: number };\n};\n\n// Action WITHOUT a payload.\nexport function undoable< TDoReturn, TUndoReturn >(\n\tactions: Actions< undefined, TDoReturn, TUndoReturn >,\n\toptions: Options< undefined, NoInfer< TDoReturn > >\n): () => TDoReturn;\n\n// Action WITH a payload.\nexport function undoable< TPayload extends NonNullable< Payload >, TDoReturn, TUndoReturn >(\n\tactions: Actions< TPayload, TDoReturn, TUndoReturn >,\n\toptions: Options< TPayload, NoInfer< TDoReturn > >\n): ( payload: TPayload ) => TDoReturn;\n\nexport function undoable< TPayload extends Payload, TDoReturn, TUndoReturn >(\n\tactions: Actions< TPayload, TDoReturn, TUndoReturn >,\n\toptions: Options< TPayload, NoInfer< TDoReturn > >\n): ( payload?: Payload ) => TDoReturn {\n\tactions.redo ??= actions.do;\n\n\tconst _addHistoryItem = options.debounce ? debounce( addHistoryItem, options.debounce.wait ) : addHistoryItem;\n\n\treturn ( payload ) => {\n\t\tconst _payload = payload as TPayload;\n\t\tconst _actions = actions as Required< Actions< TPayload, TDoReturn, TUndoReturn > >;\n\n\t\tlet result = _actions.do( _payload );\n\n\t\t_addHistoryItem( {\n\t\t\ttitle: normalizeToGenerator( options.title )( _payload, result ),\n\t\t\tsubTitle: normalizeToGenerator( options.subtitle )( _payload, result ),\n\t\t\ttype: '',\n\t\t\trestore: ( _, isRedo ) => {\n\t\t\t\tif ( isRedo ) {\n\t\t\t\t\tresult = _actions.redo( _payload, result );\n\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t_actions.undo( _payload, result );\n\t\t\t},\n\t\t} );\n\n\t\treturn result;\n\t};\n}\n\nfunction normalizeToGenerator< TPayload extends Payload, TDoReturn >(\n\tvalue: string | undefined | LabelGenerator< TPayload, TDoReturn >\n) {\n\treturn typeof value === 'function' ? value : () => value ?? '';\n}\n\nfunction addHistoryItem( item: HistoryItem ) {\n\tconst history = getHistoryManager();\n\thistory.addItem( item );\n}\n","import { createError } from '@elementor/utils';\n\nexport type HistoryItem = {\n\ttitle: string;\n\tsubTitle: string;\n\ttype: string;\n\trestore: ( item: HistoryItem, isRedo: boolean ) => void;\n};\n\ntype AddHistoryItem = ( item: HistoryItem ) => void;\n\nexport type WindowWithHistoryManager = Window & {\n\telementor?: {\n\t\tdocuments?: {\n\t\t\tgetCurrent?: () => {\n\t\t\t\thistory?: {\n\t\t\t\t\taddItem: AddHistoryItem;\n\t\t\t\t};\n\t\t\t};\n\t\t};\n\t};\n};\n\nconst HistoryManagerNotAvailable = createError( {\n\tcode: 'history_manager_not_available',\n\tmessage: 'Cannot access History manager.',\n} );\n\nexport function getHistoryManager() {\n\tconst extendedWindow = window as unknown as WindowWithHistoryManager;\n\n\tconst historyManger = extendedWindow.elementor?.documents?.getCurrent?.()?.history;\n\n\tif ( ! historyManger ) {\n\t\tthrow new HistoryManagerNotAvailable();\n\t}\n\n\treturn historyManger;\n}\n","export type WindowWithDataHooks = Window & {\n\t$e: {\n\t\tmodules?: {\n\t\t\thookData?: {\n\t\t\t\t[ K in keyof HooksMap as Capitalize< K > ]: HooksMap[ K ];\n\t\t\t};\n\t\t};\n\t};\n};\n\ntype HooksMap = Record< HookType, typeof DataHook | undefined >;\n\ntype HookType = 'after' | 'dependency';\n\nexport type Args = Record< string, unknown >;\n\nexport declare class DataHook {\n\tgetCommand(): string;\n\tgetId(): string;\n\tapply( args: Args ): unknown;\n\tregister(): void;\n}\n\nlet hookId = 0;\n\nexport function registerDataHook( type: 'dependency', command: string, callback: ( args: Args ) => boolean ): DataHook;\n\nexport function registerDataHook(\n\ttype: 'after',\n\tcommand: string,\n\tcallback: ( args: Args ) => void | Promise< void >\n): DataHook;\n\nexport function registerDataHook( type: HookType, command: string, callback: ( args: Args ) => unknown ): DataHook {\n\tconst eWindow = window as unknown as WindowWithDataHooks;\n\tconst hooksClasses = eWindow.$e?.modules?.hookData;\n\n\tconst hooksMap = {\n\t\tafter: hooksClasses?.After,\n\t\tdependency: hooksClasses?.Dependency,\n\t} satisfies HooksMap;\n\n\tconst HookClass = hooksMap[ type ];\n\n\tif ( ! HookClass ) {\n\t\tthrow new Error( `Data hook '${ type }' is not available` );\n\t}\n\n\tconst currentHookId = ++hookId;\n\n\tconst hook = new ( class extends HookClass {\n\t\tgetCommand() {\n\t\t\treturn command;\n\t\t}\n\n\t\tgetId() {\n\t\t\treturn `${ command }--data--${ currentHookId }`;\n\t\t}\n\n\t\tapply( args: Args ) {\n\t\t\treturn callback( args );\n\t\t}\n\t} )();\n\n\thook.register();\n\n\treturn hook;\n}\n","import { type Args, registerDataHook } from './register-data-hook';\n\ntype BlockCommandArgs = {\n\tcommand: string;\n\tcondition: ( args: Args ) => boolean;\n};\n\nexport function blockCommand( { command, condition }: BlockCommandArgs ) {\n\treturn registerDataHook( 'dependency', command, ( args ) => {\n\t\tconst shouldBlock = condition( args );\n\n\t\t// Should return `false` to prevent the command from running.\n\t\treturn ! shouldBlock;\n\t} );\n}\n"],"mappings":";AAEO,SAAS,iBAAuB,OAA+C;AAIrF,SACC,CAAC,CAAE,SACH,aAAa,OAAO,SACpB,OAAO,OAAQ,OAAO,SAAU,KAChC,OAAO,OAAQ,OAAO,MAAO,KAC7B,OAAO,OAAQ,OAAO,MAAO;AAE/B;AAEO,SAAS,wBAA8B,UAA8C;AAC3F,SAAO,IAAI,QAAS,CAAE,SAAS,WAAY;AAC1C,aAAS,KAAM,SAAS,MAAO;AAAA,EAChC,CAAE;AACH;;;ACZA,eAAsB,WAAY,SAAiB,MAAe,EAAE,WAAW,MAAM,IAAuB,CAAC,GAAI;AAChH,QAAM,SAAS,eAAgB,SAAS,MAAM,EAAE,SAAS,CAAE;AAE3D,MAAK,kBAAkB,SAAU;AAChC,WAAO;AAAA,EACR;AAEA,MAAK,iBAAkB,MAAO,GAAI;AACjC,WAAO,wBAAyB,MAAO;AAAA,EACxC;AAEA,SAAO,QAAQ,QAAS,MAAO;AAChC;AAEO,SAAS,eAAgB,SAAiB,MAAe,EAAE,WAAW,MAAM,IAAuB,CAAC,GAAI;AAC9G,QAAM,iBAAiB;AAEvB,QAAM,MAAM,WAAW,eAAe,IAAI,WAAW,eAAe,IAAI;AAExE,MAAK,CAAE,KAAM;AACZ,UAAM,aAAa,WAAW,gBAAgB;AAE9C,UAAM,IAAI,MAAO,KAAM,UAAW,uBAAwB;AAAA,EAC3D;AAEA,SAAO,IAAK,SAAS,IAAK;AAC3B;AAEO,SAAS,UAAW,OAAgB;AAC1C,QAAM,iBAAiB;AAEvB,MAAK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": "3.32.0-20",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "Elementor Team",
|
|
6
6
|
"homepage": "https://elementor.com/",
|
|
@@ -18,11 +18,11 @@
|
|
|
18
18
|
},
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|
|
21
|
-
"url": "git+https://github.com/elementor/elementor
|
|
21
|
+
"url": "git+https://github.com/elementor/elementor.git",
|
|
22
22
|
"directory": "packages/core/editor-v1-adapters"
|
|
23
23
|
},
|
|
24
24
|
"bugs": {
|
|
25
|
-
"url": "https://github.com/elementor/elementor
|
|
25
|
+
"url": "https://github.com/elementor/elementor/issues"
|
|
26
26
|
},
|
|
27
27
|
"publishConfig": {
|
|
28
28
|
"access": "public"
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"dev": "tsup --config=../../tsup.dev.ts"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@elementor/utils": "
|
|
42
|
+
"@elementor/utils": "3.32.0-20"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"react": "^18.3.1"
|
package/src/index.ts
CHANGED
|
@@ -27,7 +27,7 @@ export {
|
|
|
27
27
|
|
|
28
28
|
export type * from './listeners';
|
|
29
29
|
|
|
30
|
-
export { isRouteActive as __privateIsRouteActive, isExperimentActive } from './readers';
|
|
30
|
+
export { isRouteActive as __privateIsRouteActive, isExperimentActive, EXPERIMENTAL_FEATURES } from './readers';
|
|
31
31
|
|
|
32
32
|
export { undoable } from './undoable';
|
|
33
33
|
|
package/src/readers/index.ts
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
import { type ExtendedWindow } from './types';
|
|
2
2
|
|
|
3
|
+
export const EXPERIMENTAL_FEATURES = {
|
|
4
|
+
CUSTOM_CSS: 'atomic_custom_css',
|
|
5
|
+
TRANSITIONS: 'atomic_widgets_should_use_transition',
|
|
6
|
+
UNSTABLE_REPEATER: 'e_unstable_repeater',
|
|
7
|
+
};
|
|
8
|
+
|
|
3
9
|
export function isRouteActive( route: string ) {
|
|
4
10
|
const extendedWindow = window as unknown as ExtendedWindow;
|
|
5
11
|
|
|
6
12
|
return !! extendedWindow.$e?.routes?.isPartOf( route );
|
|
7
13
|
}
|
|
8
14
|
|
|
9
|
-
export const isExperimentActive = ( experiment: string ) => {
|
|
15
|
+
export const isExperimentActive = ( experiment: keyof typeof EXPERIMENTAL_FEATURES | string ) => {
|
|
10
16
|
const extendedWindow = window as unknown as ExtendedWindow;
|
|
11
17
|
|
|
12
18
|
return !! extendedWindow.elementorCommon?.config?.experimentalFeatures?.[ experiment ];
|
package/src/undoable/undoable.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { debounce } from '@elementor/utils';
|
|
2
|
+
|
|
3
|
+
import { getHistoryManager, type HistoryItem } from './get-history-manager';
|
|
2
4
|
|
|
3
5
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4
6
|
type Payload = Record< string, any > | undefined;
|
|
@@ -14,6 +16,7 @@ type Actions< TPayload extends Payload, TDoReturn, TUndoReturn > = {
|
|
|
14
16
|
type Options< TPayload extends Payload, TDoReturn > = {
|
|
15
17
|
title: string | LabelGenerator< TPayload, TDoReturn >;
|
|
16
18
|
subtitle?: string | LabelGenerator< TPayload, TDoReturn >;
|
|
19
|
+
debounce?: { wait: number };
|
|
17
20
|
};
|
|
18
21
|
|
|
19
22
|
// Action WITHOUT a payload.
|
|
@@ -34,15 +37,15 @@ export function undoable< TPayload extends Payload, TDoReturn, TUndoReturn >(
|
|
|
34
37
|
): ( payload?: Payload ) => TDoReturn {
|
|
35
38
|
actions.redo ??= actions.do;
|
|
36
39
|
|
|
40
|
+
const _addHistoryItem = options.debounce ? debounce( addHistoryItem, options.debounce.wait ) : addHistoryItem;
|
|
41
|
+
|
|
37
42
|
return ( payload ) => {
|
|
38
43
|
const _payload = payload as TPayload;
|
|
39
44
|
const _actions = actions as Required< Actions< TPayload, TDoReturn, TUndoReturn > >;
|
|
40
45
|
|
|
41
|
-
const history = getHistoryManager();
|
|
42
|
-
|
|
43
46
|
let result = _actions.do( _payload );
|
|
44
47
|
|
|
45
|
-
|
|
48
|
+
_addHistoryItem( {
|
|
46
49
|
title: normalizeToGenerator( options.title )( _payload, result ),
|
|
47
50
|
subTitle: normalizeToGenerator( options.subtitle )( _payload, result ),
|
|
48
51
|
type: '',
|
|
@@ -66,3 +69,8 @@ function normalizeToGenerator< TPayload extends Payload, TDoReturn >(
|
|
|
66
69
|
) {
|
|
67
70
|
return typeof value === 'function' ? value : () => value ?? '';
|
|
68
71
|
}
|
|
72
|
+
|
|
73
|
+
function addHistoryItem( item: HistoryItem ) {
|
|
74
|
+
const history = getHistoryManager();
|
|
75
|
+
history.addItem( item );
|
|
76
|
+
}
|