@wix/editor-application 1.63.0 → 1.64.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.
- package/dist/cjs/index.js +1 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +1 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/statics/index.js +1 -2
- package/dist/statics/index.js.map +1 -1
- package/dist/types/index.d.ts +12 -8
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/cjs/index.js
CHANGED
|
@@ -106,8 +106,7 @@ class EditorPlatformApplication {
|
|
|
106
106
|
constructor(type, context) {
|
|
107
107
|
this.type = type;
|
|
108
108
|
this.#context = context;
|
|
109
|
-
|
|
110
|
-
this.appDefinitionId = bindings.appDefinitionId;
|
|
109
|
+
this.appDefinitionId = this.#context.getAppDefinitionId();
|
|
111
110
|
const events = this.#context.getEvents();
|
|
112
111
|
this.lifecycle = new ApplicationLifecycle(events);
|
|
113
112
|
events.addEventListener(publicEditorPlatformInterfaces.EventType.removeAppCompleted, (e) => {
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/hash.ts","../../src/ApplicationLifecycle/ApplicationLifecycle.ts","../../src/errors.ts","../../src/EditorPlatformApplication/EditorPlatformApplication.ts","../../src/types.ts","../../src/EditorPlatformApplication/WixEditorPlatformApplication.ts","../../src/EditorPlatformApplication/WixEditorPlatformAddon.ts"],"sourcesContent":["/**\n * it would be good to use performance.now()\n * but it some cases performance API is not available\n */\nexport function hash() {\n const _performance = globalThis['performance'];\n\n if (_performance && _performance.now) {\n return _performance.now();\n }\n\n let result = '';\n const characters =\n 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';\n\n const charactersLength = characters.length;\n\n let counter = 0;\n\n const length = 10;\n while (counter < length) {\n result += characters.charAt(Math.floor(Math.random() * charactersLength));\n counter += 1;\n }\n\n return result;\n}\n","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","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","export enum ApplicationType {\n EditorAddon = 'EDITOR_ADDON',\n Platform = 'PLATFORM',\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":["PlatformAppEvent","EditorPlatformApplicationErrorCode","BaseError","createErrorBuilder","EventType","ApplicationType","ApplicationContext"],"mappings":";;;;;;;AAIO,SAAS,IAAO,GAAA;AACrB,EAAM,MAAA,YAAA,GAAe,WAAW,aAAa,CAAA,CAAA;AAE7C,EAAI,IAAA,YAAA,IAAgB,aAAa,GAAK,EAAA;AACpC,IAAA,OAAO,aAAa,GAAI,EAAA,CAAA;AAAA,GAC1B;AAEA,EAAA,IAAI,MAAS,GAAA,EAAA,CAAA;AACb,EAAA,MAAM,UACJ,GAAA,gEAAA,CAAA;AAEF,EAAA,MAAM,mBAAmB,UAAW,CAAA,MAAA,CAAA;AAEpC,EAAA,IAAI,OAAU,GAAA,CAAA,CAAA;AAEd,EAAA,MAAM,MAAS,GAAA,EAAA,CAAA;AACf,EAAA,OAAO,UAAU,MAAQ,EAAA;AACvB,IAAU,MAAA,IAAA,UAAA,CAAW,OAAO,IAAK,CAAA,KAAA,CAAM,KAAK,MAAO,EAAA,GAAI,gBAAgB,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iB,EAAA;AACrC,IAAO,OAAA,oCAAA;AAAA,MACL,kCAAmC,CAAA,uBAAA;AAAA,MACnC,OAAA;AAAA,KACF,CAAE,mBAAoB,CAAA,IAAA,CAAK,eAAe,CAAA,CAAA;AAAA,GAC5C;AACF;;ACzIY,IAAA,eAAA,qBAAAK,gBAAL,KAAA;AACL,EAAAA,iBAAA,aAAc,CAAA,GAAA,cAAA,CAAA;AACd,EAAAA,iBAAA,UAAW,CAAA,GAAA,UAAA,CAAA;AAFD,EAAAA,OAAAA,gBAAAA,CAAAA;AAAA,CAAA,EAAA,eAAA,IAAA,EAAA;;ACQL,MAAM,qCAGH,yBAIR,CAAA;AAAA,EACA,aAAa,MAAsD,GAAA;AACjE,IAAA,OAAO,IAAI,4BAAA;AAAA,MACT,MAAMC,0CAAmB,WAAY,EAAA;AAAA,KACvC,CAAA;AAAA,GACF;AAAA,EAEA,YAAY,OAAwD,EAAA;AAClE,IAAM,KAAA,CAAA,eAAA,CAAgB,UAAU,OAAO,CAAA,CAAA;AAAA,GACzC;AACF;;ACjBO,MAAM,+BAGH,yBAAkE,CAAA;AAAA,EAC1E,aAAa,MAEX,GAAA;AACA,IAAM,MAAA,OAAA,GAAU,MAAMA,yCAAA,CAAmB,WAA2B,EAAA,CAAA;AAEpE,IAAO,OAAA,IAAI,uBAAgD,OAAO,CAAA,CAAA;AAAA,GACpE;AAAA,EAEA,YAAY,OAA4C,EAAA;AACtD,IAAM,KAAA,CAAA,eAAA,CAAgB,aAAa,OAAO,CAAA,CAAA;AAAA,GAC5C;AACF;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/hash.ts","../../src/ApplicationLifecycle/ApplicationLifecycle.ts","../../src/errors.ts","../../src/EditorPlatformApplication/EditorPlatformApplication.ts","../../src/types.ts","../../src/EditorPlatformApplication/WixEditorPlatformApplication.ts","../../src/EditorPlatformApplication/WixEditorPlatformAddon.ts"],"sourcesContent":["/**\n * it would be good to use performance.now()\n * but it some cases performance API is not available\n */\nexport function hash() {\n const _performance = globalThis['performance'];\n\n if (_performance && _performance.now) {\n return _performance.now();\n }\n\n let result = '';\n const characters =\n 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';\n\n const charactersLength = characters.length;\n\n let counter = 0;\n\n const length = 10;\n while (counter < length) {\n result += characters.charAt(Math.floor(Math.random() * charactersLength));\n counter += 1;\n }\n\n return result;\n}\n","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","import { PlatformAppEvent } from '@wix/public-editor-platform-events';\nimport { ApplicationContext } 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 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;\n\n protected constructor(\n public readonly type: ApplicationType,\n context: ApplicationContext,\n ) {\n this.#context = context;\n\n this.appDefinitionId = this.#context.getAppDefinitionId()!;\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","/**\n * TODO: use this enum\n * import {ApplicationContextType} from \"@wix/editor-platform-contexts\";\n */\nexport enum ApplicationType {\n EditorAddon = 'EDITOR_ADDON',\n Platform = 'PLATFORM',\n}\n","import { ApplicationContext } 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<TPublicAPI, TPrivateAPI> {\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) {\n super(ApplicationType.Platform, context);\n }\n}\n","import { ApplicationContext } 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<TPublicAPI, TPrivateAPI> {\n static async create<TPublicAPI = unknown, TPrivateAPI = unknown>(): Promise<\n WixEditorPlatformAddon<TPublicAPI, TPrivateAPI>\n > {\n const context = await ApplicationContext.getInstance();\n\n return new WixEditorPlatformAddon<TPublicAPI, TPrivateAPI>(context);\n }\n\n constructor(context: ApplicationContext) {\n super(ApplicationType.EditorAddon, context);\n }\n}\n"],"names":["PlatformAppEvent","EditorPlatformApplicationErrorCode","BaseError","createErrorBuilder","EventType","ApplicationType","ApplicationContext"],"mappings":";;;;;;;AAIO,SAAS,IAAO,GAAA;AACrB,EAAM,MAAA,YAAA,GAAe,WAAW,aAAa,CAAA,CAAA;AAE7C,EAAI,IAAA,YAAA,IAAgB,aAAa,GAAK,EAAA;AACpC,IAAA,OAAO,aAAa,GAAI,EAAA,CAAA;AAAA,GAC1B;AAEA,EAAA,IAAI,MAAS,GAAA,EAAA,CAAA;AACb,EAAA,MAAM,UACJ,GAAA,gEAAA,CAAA;AAEF,EAAA,MAAM,mBAAmB,UAAW,CAAA,MAAA,CAAA;AAEpC,EAAA,IAAI,OAAU,GAAA,CAAA,CAAA;AAEd,EAAA,MAAM,MAAS,GAAA,EAAA,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AAA,OAAA,CAAA;AAAA,GAC9B;AAAA,EAEO,KAAQ,GAAA;AAAA,GAAC;AAAA,EAEhB,sBAAsB,OAAiB,EAAA;AACrC,IAAO,OAAA,oCAAA;AAAA,MACL,kCAAmC,CAAA,uBAAA;AAAA,MACnC,OAAA;AAAA,KACF,CAAE,mBAAoB,CAAA,IAAA,CAAK,eAAe,CAAA,CAAA;AAAA,GAC5C;AACF;;AChIY,IAAA,eAAA,qBAAAK,gBAAL,KAAA;AACL,EAAAA,iBAAA,aAAc,CAAA,GAAA,cAAA,CAAA;AACd,EAAAA,iBAAA,UAAW,CAAA,GAAA,UAAA,CAAA;AAFD,EAAAA,OAAAA,gBAAAA,CAAAA;AAAA,CAAA,EAAA,eAAA,IAAA,EAAA;;ACCL,MAAM,qCAGH,yBAAmD,CAAA;AAAA,EAC3D,aAAa,MAAsD,GAAA;AACjE,IAAA,OAAO,IAAI,4BAAA;AAAA,MACT,MAAMC,0CAAmB,WAAY,EAAA;AAAA,KACvC,CAAA;AAAA,GACF;AAAA,EAEA,YAAY,OAA6B,EAAA;AACvC,IAAM,KAAA,CAAA,eAAA,CAAgB,UAAU,OAAO,CAAA,CAAA;AAAA,GACzC;AACF;;ACbO,MAAM,+BAGH,yBAAmD,CAAA;AAAA,EAC3D,aAAa,MAEX,GAAA;AACA,IAAM,MAAA,OAAA,GAAU,MAAMA,yCAAA,CAAmB,WAAY,EAAA,CAAA;AAErD,IAAO,OAAA,IAAI,uBAAgD,OAAO,CAAA,CAAA;AAAA,GACpE;AAAA,EAEA,YAAY,OAA6B,EAAA;AACvC,IAAM,KAAA,CAAA,eAAA,CAAgB,aAAa,OAAO,CAAA,CAAA;AAAA,GAC5C;AACF;;;;;;;"}
|
package/dist/esm/index.js
CHANGED
|
@@ -104,8 +104,7 @@ class EditorPlatformApplication {
|
|
|
104
104
|
constructor(type, context) {
|
|
105
105
|
this.type = type;
|
|
106
106
|
this.#context = context;
|
|
107
|
-
|
|
108
|
-
this.appDefinitionId = bindings.appDefinitionId;
|
|
107
|
+
this.appDefinitionId = this.#context.getAppDefinitionId();
|
|
109
108
|
const events = this.#context.getEvents();
|
|
110
109
|
this.lifecycle = new ApplicationLifecycle(events);
|
|
111
110
|
events.addEventListener(EventType.removeAppCompleted, (e) => {
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/hash.ts","../../src/ApplicationLifecycle/ApplicationLifecycle.ts","../../src/errors.ts","../../src/EditorPlatformApplication/EditorPlatformApplication.ts","../../src/types.ts","../../src/EditorPlatformApplication/WixEditorPlatformApplication.ts","../../src/EditorPlatformApplication/WixEditorPlatformAddon.ts"],"sourcesContent":["/**\n * it would be good to use performance.now()\n * but it some cases performance API is not available\n */\nexport function hash() {\n const _performance = globalThis['performance'];\n\n if (_performance && _performance.now) {\n return _performance.now();\n }\n\n let result = '';\n const characters =\n 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';\n\n const charactersLength = characters.length;\n\n let counter = 0;\n\n const length = 10;\n while (counter < length) {\n result += characters.charAt(Math.floor(Math.random() * charactersLength));\n counter += 1;\n }\n\n return result;\n}\n","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","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","export enum ApplicationType {\n EditorAddon = 'EDITOR_ADDON',\n Platform = 'PLATFORM',\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":["EditorPlatformApplicationErrorCode","ApplicationType"],"mappings":";;;;;AAIO,SAAS,IAAO,GAAA;AACrB,EAAM,MAAA,YAAA,GAAe,WAAW,aAAa,CAAA,CAAA;AAE7C,EAAI,IAAA,YAAA,IAAgB,aAAa,GAAK,EAAA;AACpC,IAAA,OAAO,aAAa,GAAI,EAAA,CAAA;AAAA,GAC1B;AAEA,EAAA,IAAI,MAAS,GAAA,EAAA,CAAA;AACb,EAAA,MAAM,UACJ,GAAA,gEAAA,CAAA;AAEF,EAAA,MAAM,mBAAmB,UAAW,CAAA,MAAA,CAAA;AAEpC,EAAA,IAAI,OAAU,GAAA,CAAA,CAAA;AAEd,EAAA,MAAM,MAAS,GAAA,EAAA,CAAA;AACf,EAAA,OAAO,UAAU,MAAQ,EAAA;AACvB,IAAU,MAAA,IAAA,UAAA,CAAW,OAAO,IAAK,CAAA,KAAA,CAAM,KAAK,MAAO,EAAA,GAAI,gBAAgB,CAAC,CAAA,CAAA;AACxE,IAAW,OAAA,IAAA,CAAA,CAAA;AAAA,GACb;AAEA,EAAO,OAAA,MAAA,CAAA;AACT;;ACnBO,MAAM,oBAAqB,CAAA;AAAA,EAWhC,YAAoB,MAAgC,EAAA;AAAhC,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA,CAAA;AAClB,IAAA,IAAA,CAAK,SAAU,EAAA,CAAA;AAAA,GACjB;AAAA,EAZQ,YAQJ,EAAC,CAAA;AAAA,EAMG,SAAY,GAAA;AAClB,IAAK,IAAA,CAAA,MAAA,CAAO,SAAU,CAAA,CAAC,KAAU,KAAA;AAC/B,MAAM,MAAA,EAAE,IAAM,EAAA,OAAA,EAAY,GAAA,KAAA,CAAA;AAC1B,MAAI,IAAA,IAAA,CAAK,SAAU,CAAA,IAAI,CAAG,EAAA;AACxB,QAAK,IAAA,CAAA,SAAA,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OAAwD,EAAA;AAClE,IAAM,KAAA,CAAA,eAAA,CAAgB,UAAU,OAAO,CAAA,CAAA;AAAA,GACzC;AACF;;ACjBO,MAAM,+BAGH,yBAAkE,CAAA;AAAA,EAC1E,aAAa,MAEX,GAAA;AACA,IAAM,MAAA,OAAA,GAAU,MAAM,kBAAA,CAAmB,WAA2B,EAAA,CAAA;AAEpE,IAAO,OAAA,IAAI,uBAAgD,OAAO,CAAA,CAAA;AAAA,GACpE;AAAA,EAEA,YAAY,OAA4C,EAAA;AACtD,IAAM,KAAA,CAAA,eAAA,CAAgB,aAAa,OAAO,CAAA,CAAA;AAAA,GAC5C;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/hash.ts","../../src/ApplicationLifecycle/ApplicationLifecycle.ts","../../src/errors.ts","../../src/EditorPlatformApplication/EditorPlatformApplication.ts","../../src/types.ts","../../src/EditorPlatformApplication/WixEditorPlatformApplication.ts","../../src/EditorPlatformApplication/WixEditorPlatformAddon.ts"],"sourcesContent":["/**\n * it would be good to use performance.now()\n * but it some cases performance API is not available\n */\nexport function hash() {\n const _performance = globalThis['performance'];\n\n if (_performance && _performance.now) {\n return _performance.now();\n }\n\n let result = '';\n const characters =\n 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';\n\n const charactersLength = characters.length;\n\n let counter = 0;\n\n const length = 10;\n while (counter < length) {\n result += characters.charAt(Math.floor(Math.random() * charactersLength));\n counter += 1;\n }\n\n return result;\n}\n","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","import { PlatformAppEvent } from '@wix/public-editor-platform-events';\nimport { ApplicationContext } 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 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;\n\n protected constructor(\n public readonly type: ApplicationType,\n context: ApplicationContext,\n ) {\n this.#context = context;\n\n this.appDefinitionId = this.#context.getAppDefinitionId()!;\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","/**\n * TODO: use this enum\n * import {ApplicationContextType} from \"@wix/editor-platform-contexts\";\n */\nexport enum ApplicationType {\n EditorAddon = 'EDITOR_ADDON',\n Platform = 'PLATFORM',\n}\n","import { ApplicationContext } 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<TPublicAPI, TPrivateAPI> {\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) {\n super(ApplicationType.Platform, context);\n }\n}\n","import { ApplicationContext } 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<TPublicAPI, TPrivateAPI> {\n static async create<TPublicAPI = unknown, TPrivateAPI = unknown>(): Promise<\n WixEditorPlatformAddon<TPublicAPI, TPrivateAPI>\n > {\n const context = await ApplicationContext.getInstance();\n\n return new WixEditorPlatformAddon<TPublicAPI, TPrivateAPI>(context);\n }\n\n constructor(context: ApplicationContext) {\n super(ApplicationType.EditorAddon, context);\n }\n}\n"],"names":["EditorPlatformApplicationErrorCode","ApplicationType"],"mappings":";;;;;AAIO,SAAS,IAAO,GAAA;AACrB,EAAM,MAAA,YAAA,GAAe,WAAW,aAAa,CAAA,CAAA;AAE7C,EAAI,IAAA,YAAA,IAAgB,aAAa,GAAK,EAAA;AACpC,IAAA,OAAO,aAAa,GAAI,EAAA,CAAA;AAAA,GAC1B;AAEA,EAAA,IAAI,MAAS,GAAA,EAAA,CAAA;AACb,EAAA,MAAM,UACJ,GAAA,gEAAA,CAAA;AAEF,EAAA,MAAM,mBAAmB,UAAW,CAAA,MAAA,CAAA;AAEpC,EAAA,IAAI,OAAU,GAAA,CAAA,CAAA;AAEd,EAAA,MAAM,MAAS,GAAA,EAAA,CAAA;AACf,EAAA,OAAO,UAAU,MAAQ,EAAA;AACvB,IAAU,MAAA,IAAA,UAAA,CAAW,OAAO,IAAK,CAAA,KAAA,CAAM,KAAK,MAAO,EAAA,GAAI,gBAAgB,CAAC,CAAA,CAAA;AACxE,IAAW,OAAA,IAAA,CAAA,CAAA;AAAA,GACb;AAEA,EAAO,OAAA,MAAA,CAAA;AACT;;ACnBO,MAAM,oBAAqB,CAAA;AAAA,EAWhC,YAAoB,MAAgC,EAAA;AAAhC,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA,CAAA;AAClB,IAAA,IAAA,CAAK,SAAU,EAAA,CAAA;AAAA,GACjB;AAAA,EAZQ,YAQJ,EAAC,CAAA;AAAA,EAMG,SAAY,GAAA;AAClB,IAAK,IAAA,CAAA,MAAA,CAAO,SAAU,CAAA,CAAC,KAAU,KAAA;AAC/B,MAAM,MAAA,EAAE,IAAM,EAAA,OAAA,EAAY,GAAA,KAAA,CAAA;AAC1B,MAAI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AAA;AAAA,GACF;AAAA,EAEA,YAAY,OAA6B,EAAA;AACvC,IAAM,KAAA,CAAA,eAAA,CAAgB,UAAU,OAAO,CAAA,CAAA;AAAA,GACzC;AACF;;ACbO,MAAM,+BAGH,yBAAmD,CAAA;AAAA,EAC3D,aAAa,MAEX,GAAA;AACA,IAAM,MAAA,OAAA,GAAU,MAAM,kBAAA,CAAmB,WAAY,EAAA,CAAA;AAErD,IAAO,OAAA,IAAI,uBAAgD,OAAO,CAAA,CAAA;AAAA,GACpE;AAAA,EAEA,YAAY,OAA6B,EAAA;AACvC,IAAM,KAAA,CAAA,eAAA,CAAgB,aAAa,OAAO,CAAA,CAAA;AAAA,GAC5C;AACF;;;;"}
|
package/dist/statics/index.js
CHANGED
|
@@ -105,8 +105,7 @@
|
|
|
105
105
|
constructor(type, context) {
|
|
106
106
|
this.type = type;
|
|
107
107
|
this.#context = context;
|
|
108
|
-
|
|
109
|
-
this.appDefinitionId = bindings.appDefinitionId;
|
|
108
|
+
this.appDefinitionId = this.#context.getAppDefinitionId();
|
|
110
109
|
const events = this.#context.getEvents();
|
|
111
110
|
this.lifecycle = new ApplicationLifecycle(events);
|
|
112
111
|
events.addEventListener(publicEditorPlatformInterfaces.EventType.removeAppCompleted, (e) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/hash.ts","../../src/ApplicationLifecycle/ApplicationLifecycle.ts","../../src/errors.ts","../../src/EditorPlatformApplication/EditorPlatformApplication.ts","../../src/types.ts","../../src/EditorPlatformApplication/WixEditorPlatformApplication.ts","../../src/EditorPlatformApplication/WixEditorPlatformAddon.ts"],"sourcesContent":["/**\n * it would be good to use performance.now()\n * but it some cases performance API is not available\n */\nexport function hash() {\n const _performance = globalThis['performance'];\n\n if (_performance && _performance.now) {\n return _performance.now();\n }\n\n let result = '';\n const characters =\n 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';\n\n const charactersLength = characters.length;\n\n let counter = 0;\n\n const length = 10;\n while (counter < length) {\n result += characters.charAt(Math.floor(Math.random() * charactersLength));\n counter += 1;\n }\n\n return result;\n}\n","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","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","export enum ApplicationType {\n EditorAddon = 'EDITOR_ADDON',\n Platform = 'PLATFORM',\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":["PlatformAppEvent","EditorPlatformApplicationErrorCode","BaseError","createErrorBuilder","EventType","ApplicationType","ApplicationContext"],"mappings":";;;;;;EAIO,SAAS,IAAO,GAAA;EACrB,EAAM,MAAA,YAAA,GAAe,WAAW,aAAa,CAAA,CAAA;EAE7C,EAAI,IAAA,YAAA,IAAgB,aAAa,GAAK,EAAA;EACpC,IAAA,OAAO,aAAa,GAAI,EAAA,CAAA;EAAA,GAC1B;EAEA,EAAA,IAAI,MAAS,GAAA,EAAA,CAAA;EACb,EAAA,MAAM,UACJ,GAAA,gEAAA,CAAA;EAEF,EAAA,MAAM,mBAAmB,UAAW,CAAA,MAAA,CAAA;EAEpC,EAAA,IAAI,OAAU,GAAA,CAAA,CAAA;EAEd,EAAA,MAAM,MAAS,GAAA,EAAA,CAAA;EACf,EAAA,OAAO,UAAU,MAAQ,EAAA;EACvB,IAAU,MAA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,CAAA;EAAA,GAC9B;EAAA,EAEO,KAAQ,GAAA;EAAA,GAAC;EAAA,EAEhB,sBAAsB,OAAiB,EAAA;EACrC,IAAO,OAAA,oCAAA;EAAA,MACL,kCAAmC,CAAA,uBAAA;EAAA,MACnC,OAAA;EAAA,KACF,CAAE,mBAAoB,CAAA,IAAA,CAAK,eAAe,CAAA,CAAA;EAAA,GAC5C;EACF;;ACzIY,MAAA,eAAA,qBAAAK,gBAAL,KAAA;EACL,EAAAA,iBAAA,aAAc,CAAA,GAAA,cAAA,CAAA;EACd,EAAAA,iBAAA,UAAW,CAAA,GAAA,UAAA,CAAA;EAFD,EAAAA,OAAAA,gBAAAA,CAAAA;EAAA,CAAA,EAAA,eAAA,IAAA,EAAA;;ECQL,MAAM,qCAGH,yBAIR,CAAA;EAAA,EACA,aAAa,MAAsD,GAAA;EACjE,IAAA,OAAO,IAAI,4BAAA;EAAA,MACT,MAAMC,0CAAmB,WAAY,EAAA;EAAA,KACvC,CAAA;EAAA,GACF;EAAA,EAEA,YAAY,OAAwD,EAAA;EAClE,IAAM,KAAA,CAAA,eAAA,CAAgB,UAAU,OAAO,CAAA,CAAA;EAAA,GACzC;EACF;;ECjBO,MAAM,+BAGH,yBAAkE,CAAA;EAAA,EAC1E,aAAa,MAEX,GAAA;EACA,IAAM,MAAA,OAAA,GAAU,MAAMA,yCAAA,CAAmB,WAA2B,EAAA,CAAA;EAEpE,IAAO,OAAA,IAAI,uBAAgD,OAAO,CAAA,CAAA;EAAA,GACpE;EAAA,EAEA,YAAY,OAA4C,EAAA;EACtD,IAAM,KAAA,CAAA,eAAA,CAAgB,aAAa,OAAO,CAAA,CAAA;EAAA,GAC5C;EACF;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/hash.ts","../../src/ApplicationLifecycle/ApplicationLifecycle.ts","../../src/errors.ts","../../src/EditorPlatformApplication/EditorPlatformApplication.ts","../../src/types.ts","../../src/EditorPlatformApplication/WixEditorPlatformApplication.ts","../../src/EditorPlatformApplication/WixEditorPlatformAddon.ts"],"sourcesContent":["/**\n * it would be good to use performance.now()\n * but it some cases performance API is not available\n */\nexport function hash() {\n const _performance = globalThis['performance'];\n\n if (_performance && _performance.now) {\n return _performance.now();\n }\n\n let result = '';\n const characters =\n 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';\n\n const charactersLength = characters.length;\n\n let counter = 0;\n\n const length = 10;\n while (counter < length) {\n result += characters.charAt(Math.floor(Math.random() * charactersLength));\n counter += 1;\n }\n\n return result;\n}\n","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","import { PlatformAppEvent } from '@wix/public-editor-platform-events';\nimport { ApplicationContext } 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 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;\n\n protected constructor(\n public readonly type: ApplicationType,\n context: ApplicationContext,\n ) {\n this.#context = context;\n\n this.appDefinitionId = this.#context.getAppDefinitionId()!;\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","/**\n * TODO: use this enum\n * import {ApplicationContextType} from \"@wix/editor-platform-contexts\";\n */\nexport enum ApplicationType {\n EditorAddon = 'EDITOR_ADDON',\n Platform = 'PLATFORM',\n}\n","import { ApplicationContext } 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<TPublicAPI, TPrivateAPI> {\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) {\n super(ApplicationType.Platform, context);\n }\n}\n","import { ApplicationContext } 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<TPublicAPI, TPrivateAPI> {\n static async create<TPublicAPI = unknown, TPrivateAPI = unknown>(): Promise<\n WixEditorPlatformAddon<TPublicAPI, TPrivateAPI>\n > {\n const context = await ApplicationContext.getInstance();\n\n return new WixEditorPlatformAddon<TPublicAPI, TPrivateAPI>(context);\n }\n\n constructor(context: ApplicationContext) {\n super(ApplicationType.EditorAddon, context);\n }\n}\n"],"names":["PlatformAppEvent","EditorPlatformApplicationErrorCode","BaseError","createErrorBuilder","EventType","ApplicationType","ApplicationContext"],"mappings":";;;;;;EAIO,SAAS,IAAO,GAAA;EACrB,EAAM,MAAA,YAAA,GAAe,WAAW,aAAa,CAAA,CAAA;EAE7C,EAAI,IAAA,YAAA,IAAgB,aAAa,GAAK,EAAA;EACpC,IAAA,OAAO,aAAa,GAAI,EAAA,CAAA;EAAA,GAC1B;EAEA,EAAA,IAAI,MAAS,GAAA,EAAA,CAAA;EACb,EAAA,MAAM,UACJ,GAAA,gEAAA,CAAA;EAEF,EAAA,MAAM,mBAAmB,UAAW,CAAA,MAAA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platform_errors from '@wix/public-editor-platform-errors';
|
|
2
2
|
import * as _wix_editor_platform_contexts from '@wix/editor-platform-contexts';
|
|
3
|
-
import { ApplicationBoundEvents,
|
|
3
|
+
import { ApplicationBoundEvents, ApplicationContext } from '@wix/editor-platform-contexts';
|
|
4
4
|
import { IPlatformEditorReadyEvent } from '@wix/public-editor-platform-events';
|
|
5
5
|
|
|
6
6
|
declare class ApplicationLifecycle {
|
|
@@ -21,6 +21,10 @@ declare enum EditorPlatformApplicationErrorCode {
|
|
|
21
21
|
ApplicationRuntimeError = "ApplicationRuntimeError"
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
/**
|
|
25
|
+
* TODO: use this enum
|
|
26
|
+
* import {ApplicationContextType} from "@wix/editor-platform-contexts";
|
|
27
|
+
*/
|
|
24
28
|
declare enum ApplicationType {
|
|
25
29
|
EditorAddon = "EDITOR_ADDON",
|
|
26
30
|
Platform = "PLATFORM"
|
|
@@ -46,14 +50,14 @@ declare class ChainAPIConfiguration<TPublicAPI, TPrivateAPI> {
|
|
|
46
50
|
/**
|
|
47
51
|
* TODO: should accept generic type
|
|
48
52
|
*/
|
|
49
|
-
declare abstract class EditorPlatformApplication<
|
|
53
|
+
declare abstract class EditorPlatformApplication<TPublicAPI = unknown, TPrivateAPI = unknown> {
|
|
50
54
|
#private;
|
|
51
55
|
readonly type: ApplicationType;
|
|
52
56
|
appDefinitionId: string;
|
|
53
57
|
state: 'READY' | 'REMOVED';
|
|
54
58
|
lifecycle: ApplicationLifecycle;
|
|
55
|
-
protected constructor(type: ApplicationType, context: ApplicationContext
|
|
56
|
-
protected get context(): ApplicationContext
|
|
59
|
+
protected constructor(type: ApplicationType, context: ApplicationContext);
|
|
60
|
+
protected get context(): ApplicationContext;
|
|
57
61
|
get events(): _wix_editor_platform_contexts.ApplicationBoundEvents;
|
|
58
62
|
setManifest(manifest: any): void;
|
|
59
63
|
getManifest(): any;
|
|
@@ -92,14 +96,14 @@ declare abstract class EditorPlatformApplication<TContext extends IApplicationCo
|
|
|
92
96
|
};
|
|
93
97
|
}
|
|
94
98
|
|
|
95
|
-
declare class WixEditorPlatformApplication<TPublicAPI = unknown, TPrivateAPI = unknown> extends EditorPlatformApplication<
|
|
99
|
+
declare class WixEditorPlatformApplication<TPublicAPI = unknown, TPrivateAPI = unknown> extends EditorPlatformApplication<TPublicAPI, TPrivateAPI> {
|
|
96
100
|
static create<TPublicAPI = unknown, TPrivateAPI = unknown>(): Promise<WixEditorPlatformApplication<TPublicAPI, TPrivateAPI>>;
|
|
97
|
-
constructor(context: ApplicationContext
|
|
101
|
+
constructor(context: ApplicationContext);
|
|
98
102
|
}
|
|
99
103
|
|
|
100
|
-
declare class WixEditorPlatformAddon<TPublicAPI = unknown, TPrivateAPI = unknown> extends EditorPlatformApplication<
|
|
104
|
+
declare class WixEditorPlatformAddon<TPublicAPI = unknown, TPrivateAPI = unknown> extends EditorPlatformApplication<TPublicAPI, TPrivateAPI> {
|
|
101
105
|
static create<TPublicAPI = unknown, TPrivateAPI = unknown>(): Promise<WixEditorPlatformAddon<TPublicAPI, TPrivateAPI>>;
|
|
102
|
-
constructor(context: ApplicationContext
|
|
106
|
+
constructor(context: ApplicationContext);
|
|
103
107
|
}
|
|
104
108
|
|
|
105
109
|
export { ApplicationType, EditorPlatformApplication, WixEditorPlatformAddon, WixEditorPlatformApplication };
|
|
@@ -1 +1 @@
|
|
|
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","
|
|
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","/**\n * TODO: use this enum\n * import {ApplicationContextType} from \"@wix/editor-platform-contexts\";\n */\nexport enum ApplicationType {\n EditorAddon = 'EDITOR_ADDON',\n Platform = 'PLATFORM',\n}\n","import { PlatformAppEvent } from '@wix/public-editor-platform-events';\nimport { ApplicationContext } 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 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;\n\n protected constructor(\n public readonly type: ApplicationType,\n context: ApplicationContext,\n ) {\n this.#context = context;\n\n this.appDefinitionId = this.#context.getAppDefinitionId()!;\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 { ApplicationContext } 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<TPublicAPI, TPrivateAPI> {\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) {\n super(ApplicationType.Platform, context);\n }\n}\n","import { ApplicationContext } 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<TPublicAPI, TPrivateAPI> {\n static async create<TPublicAPI = unknown, TPrivateAPI = unknown>(): Promise<\n WixEditorPlatformAddon<TPublicAPI, TPrivateAPI>\n > {\n const context = await ApplicationContext.getInstance();\n\n return new WixEditorPlatformAddon<TPublicAPI, TPrivateAPI>(context);\n }\n\n constructor(context: ApplicationContext) {\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;;ACHA;AACA;AACA;AACA;AACO;AACP;AACA;AACA;;ACHA;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.
|
|
3
|
+
"version": "1.64.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"typescript": "^5.8.3"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@wix/editor-platform-contexts": "1.
|
|
43
|
+
"@wix/editor-platform-contexts": "1.64.0",
|
|
44
44
|
"@wix/public-editor-platform-errors": "1.8.0",
|
|
45
45
|
"@wix/public-editor-platform-events": "1.313.0",
|
|
46
46
|
"@wix/public-editor-platform-interfaces": "1.23.0"
|
|
@@ -67,5 +67,5 @@
|
|
|
67
67
|
]
|
|
68
68
|
}
|
|
69
69
|
},
|
|
70
|
-
"falconPackageHash": "
|
|
70
|
+
"falconPackageHash": "a2f8233d09b29237c5cb82552c064020eceeb0f6aecebe6be618d000"
|
|
71
71
|
}
|