@wix/editor-application 1.37.0 → 1.39.0

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.
@@ -102,5 +102,6 @@ declare class WixEditorPlatformAddon<TPublicAPI = unknown, TPrivateAPI = unknown
102
102
  constructor(context: ApplicationContext<IAddonContext>);
103
103
  }
104
104
 
105
- export { ApplicationType, EditorPlatformApplication, type IApplicationAPI, type IApplicationRegistry, WixEditorPlatformAddon, WixEditorPlatformApplication };
105
+ export { ApplicationType, EditorPlatformApplication, WixEditorPlatformAddon, WixEditorPlatformApplication };
106
+ export type { IApplicationAPI, IApplicationRegistry };
106
107
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sources":[],"sourcesContent":[],"names":[],"mappings":""}
1
+ {"version":3,"file":"index.d.ts","sources":["../../src/ApplicationLifecycle/ApplicationLifecycle.ts","../../src/errors.ts","../../src/types.ts","../../src/EditorPlatformApplication/EditorPlatformApplication.ts","../../src/EditorPlatformApplication/WixEditorPlatformApplication.ts","../../src/EditorPlatformApplication/WixEditorPlatformAddon.ts"],"sourcesContent":["import {\n PlatformAppEvent,\n IPlatformEditorReadyEvent,\n} from '@wix/public-editor-platform-events';\nimport type { ApplicationBoundEvents } from '@wix/editor-platform-contexts';\nimport { hash } from '../hash';\n\nexport class ApplicationLifecycle {\n private callbacks: Partial<\n Record<\n PlatformAppEvent,\n {\n id: string;\n fn: (payload: any) => void;\n }[]\n >\n > = {};\n\n constructor(private events: ApplicationBoundEvents) {\n this.subscribe();\n }\n\n private subscribe() {\n this.events.subscribe((event) => {\n const { type, payload } = event;\n if (this.callbacks[type]) {\n this.callbacks[type]!.forEach(({ fn }) => fn(payload));\n }\n });\n }\n\n private addCallback(event: PlatformAppEvent, fn: (payload: any) => void) {\n if (!this.callbacks[event]) {\n this.callbacks[event] = [];\n }\n\n const id = `${hash()}`;\n\n this.callbacks[event]!.push({\n id,\n fn,\n });\n\n return () => {\n this.callbacks[event] = this.callbacks[event]!.filter(\n (cb) => cb.id !== id,\n );\n };\n }\n\n /**\n * NOTE: currently, we return function to unsubscribe from the event,\n * probably it is better to return `this` to allow chaining\n * and provide another way to unsubscribe from events.\n */\n public onEditorReady(\n fn: (payload: IPlatformEditorReadyEvent['payload']) => void,\n ) {\n return this.addCallback(PlatformAppEvent.EditorReady, fn);\n }\n}\n","import {\n BaseError,\n createErrorBuilder,\n} from '@wix/public-editor-platform-errors';\n\nexport enum EditorPlatformApplicationErrorCode {\n ApplicationRuntimeError = 'ApplicationRuntimeError',\n}\n\nclass EditorPlatformApplicationError extends BaseError<EditorPlatformApplicationErrorCode> {\n state: Partial<{\n url: string;\n appDefinitionId: string;\n apiMethod: string;\n apiType: string;\n }> = {};\n\n constructor(message: string, code: EditorPlatformApplicationErrorCode) {\n super(message, code, 'EP Application Error');\n }\n\n withUrl(url: string) {\n this.state = { ...this.state, url };\n return this;\n }\n\n withAppDefinitionId(appDefinitionId: string) {\n this.state = { ...this.state, appDefinitionId };\n return this;\n }\n\n withApiMethod(apiMethod: string) {\n this.state = { ...this.state, apiMethod };\n return this;\n }\n\n withApiType(apiType: string) {\n this.state = { ...this.state, apiType };\n return this;\n }\n}\n\nexport const createEditorPlatformApplicationError = createErrorBuilder<\n EditorPlatformApplicationErrorCode,\n EditorPlatformApplicationError\n>(EditorPlatformApplicationError);\n","export enum ApplicationType {\n EditorAddon = 'EDITOR_ADDON',\n Platform = 'PLATFORM',\n}\n","import { PlatformAppEvent } from '@wix/public-editor-platform-events';\nimport {\n ApplicationContext,\n IApplicationContext,\n} from '@wix/editor-platform-contexts';\nimport { EventType } from '@wix/public-editor-platform-interfaces';\nimport { ApplicationLifecycle } from '../ApplicationLifecycle';\nimport {\n createEditorPlatformApplicationError,\n EditorPlatformApplicationErrorCode,\n} from '../errors';\nimport { ApplicationType } from '../types';\n\n/**\n * TODO: duplicated type to get rid of extra dependency\n */\nexport type IApplicationRegistry = (\n instance: EditorPlatformApplication,\n) => void;\n\ndeclare global {\n // eslint-disable-next-line no-var\n var __APPLICATION_REGISTRY_KEY: IApplicationRegistry;\n}\n\nexport interface IApplicationAPI<TPublicAPI, TPrivateAPI> {\n public?: TPublicAPI;\n private?: TPrivateAPI;\n}\n\nclass ChainAPIConfiguration<TPublicAPI, TPrivateAPI> {\n constructor(private api: IApplicationAPI<TPublicAPI, TPrivateAPI>) {}\n\n exposePublicAPI(api: TPublicAPI) {\n this.api.public = api;\n return this;\n }\n\n exposePrivateAPI(api: TPrivateAPI) {\n this.api.private = api;\n return this;\n }\n}\n\n/**\n * TODO: should accept generic type\n */\nexport abstract class EditorPlatformApplication<\n TContext extends IApplicationContext = IApplicationContext,\n TPublicAPI = unknown,\n TPrivateAPI = unknown,\n> {\n public appDefinitionId: string;\n public state: 'READY' | 'REMOVED' = 'READY';\n\n public lifecycle: ApplicationLifecycle;\n\n #applicationAPI: IApplicationAPI<TPublicAPI, TPrivateAPI> = {};\n #chainAPIConfiguration = new ChainAPIConfiguration<TPublicAPI, TPrivateAPI>(\n this.#applicationAPI,\n );\n\n #manifest: any;\n #context: ApplicationContext<TContext>;\n\n protected constructor(\n public readonly type: ApplicationType,\n context: ApplicationContext<TContext>,\n ) {\n this.#context = context;\n const bindings = this.#context.getBindings();\n\n this.appDefinitionId = bindings.appDefinitionId;\n\n const events = this.#context.getEvents();\n this.lifecycle = new ApplicationLifecycle(events);\n\n /**\n * TODO: application should not listen such event, we should manage its state outside\n */\n events.addEventListener(EventType.removeAppCompleted, (e) => {\n if (e.appDefinitionId === this.appDefinitionId) {\n this.state = 'REMOVED';\n }\n });\n\n // This line is used to get the application registry from the function scope\n // that is creating dynamically by using the `new Function` constructor\n // e.g. new Function('__APPLICATION_REGISTRY_KEY', '// our app code')\n const applicationRegister = __APPLICATION_REGISTRY_KEY;\n applicationRegister(this);\n\n events.notify({\n type: PlatformAppEvent.ApplicationInit,\n payload: {},\n });\n }\n\n protected get context() {\n return this.#context;\n }\n public get events() {\n return this.#context.getEvents();\n }\n\n public setManifest(manifest: any) {\n this.#manifest = manifest;\n }\n\n public getManifest() {\n return this.#manifest;\n }\n\n public exposePublicAPI(api: TPublicAPI) {\n return this.#chainAPIConfiguration.exposePublicAPI(api);\n }\n\n public exposePrivateAPI(api: TPrivateAPI) {\n return this.#chainAPIConfiguration.exposePrivateAPI(api);\n }\n\n public getPublicAPI() {\n return this.#applicationAPI.public;\n }\n\n public getPrivateAPI() {\n return this.#applicationAPI.private;\n }\n\n public ready() {}\n\n buildApplicationError(message: string) {\n return createEditorPlatformApplicationError(\n EditorPlatformApplicationErrorCode.ApplicationRuntimeError,\n message,\n ).withAppDefinitionId(this.appDefinitionId);\n }\n}\n","import {\n ApplicationContext,\n IEditorApplicationContext,\n} from '@wix/editor-platform-contexts';\n\nimport { EditorPlatformApplication } from './EditorPlatformApplication';\nimport { ApplicationType } from '../types';\n\nexport class WixEditorPlatformApplication<\n TPublicAPI = unknown,\n TPrivateAPI = unknown,\n> extends EditorPlatformApplication<\n IEditorApplicationContext,\n TPublicAPI,\n TPrivateAPI\n> {\n static async create<TPublicAPI = unknown, TPrivateAPI = unknown>() {\n return new WixEditorPlatformApplication<TPublicAPI, TPrivateAPI>(\n await ApplicationContext.getInstance(),\n );\n }\n\n constructor(context: ApplicationContext<IEditorApplicationContext>) {\n super(ApplicationType.Platform, context);\n }\n}\n","import {\n ApplicationContext,\n IAddonContext,\n} from '@wix/editor-platform-contexts';\n\nimport { EditorPlatformApplication } from './EditorPlatformApplication';\nimport { ApplicationType } from '../types';\n\nexport class WixEditorPlatformAddon<\n TPublicAPI = unknown,\n TPrivateAPI = unknown,\n> extends EditorPlatformApplication<IAddonContext, TPublicAPI, TPrivateAPI> {\n static async create<TPublicAPI = unknown, TPrivateAPI = unknown>(): Promise<\n WixEditorPlatformAddon<TPublicAPI, TPrivateAPI>\n > {\n const context = await ApplicationContext.getInstance<IAddonContext>();\n\n return new WixEditorPlatformAddon<TPublicAPI, TPrivateAPI>(context);\n }\n\n constructor(context: ApplicationContext<IAddonContext>) {\n super(ApplicationType.EditorAddon, context);\n }\n}\n"],"names":[],"mappings":";;;;;AAEO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACbO;AACP;AACA;;ACHO;AACP;AACA;AACA;;ACCA;AACA;AACA;AACO;AACP;AACA;AACA;AACO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AClEO;AACP;AACA;AACA;;ACHO;AACP;AACA;AACA;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/editor-application",
3
- "version": "1.37.0",
3
+ "version": "1.39.0",
4
4
  "description": "",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -35,14 +35,14 @@
35
35
  "eslint": "^8.57.1",
36
36
  "prettier": "^3.5.3",
37
37
  "rollup": "^3.29.5",
38
- "rollup-plugin-dts": "^6.1.1",
38
+ "rollup-plugin-dts": "^6.2.1",
39
39
  "rollup-plugin-esbuild": "^5.0.0",
40
40
  "typescript": "^5.8.2"
41
41
  },
42
42
  "dependencies": {
43
- "@wix/editor-platform-contexts": "1.37.0",
43
+ "@wix/editor-platform-contexts": "1.39.0",
44
44
  "@wix/public-editor-platform-errors": "1.8.0",
45
- "@wix/public-editor-platform-events": "1.309.0",
45
+ "@wix/public-editor-platform-events": "1.310.0",
46
46
  "@wix/public-editor-platform-interfaces": "1.20.0"
47
47
  },
48
48
  "publishConfig": {
@@ -67,5 +67,5 @@
67
67
  ]
68
68
  }
69
69
  },
70
- "falconPackageHash": "04ff7c929a28663396c8afeed47f1f1730301c41760e50718968a2d1"
70
+ "falconPackageHash": "41ce66d1399232d0db184b6a5f5f31ea1bd6c32d544fe657c9f4494d"
71
71
  }