@webiny/website-builder-sdk 6.3.0 → 6.4.0-beta.1
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/BindingsApi.js +29 -36
- package/BindingsApi.js.map +1 -1
- package/BindingsProcessor.js +34 -43
- package/BindingsProcessor.js.map +1 -1
- package/BindingsProcessor.test.js +82 -78
- package/BindingsProcessor.test.js.map +1 -1
- package/BindingsResolver.js +92 -119
- package/BindingsResolver.js.map +1 -1
- package/BindingsResolver.test.js +399 -363
- package/BindingsResolver.test.js.map +1 -1
- package/ComponentInputTraverser.js +28 -49
- package/ComponentInputTraverser.js.map +1 -1
- package/ComponentManifestToAstConverter.js +20 -21
- package/ComponentManifestToAstConverter.js.map +1 -1
- package/ComponentRegistry.js +26 -45
- package/ComponentRegistry.js.map +1 -1
- package/ComponentResolver.js +25 -29
- package/ComponentResolver.js.map +1 -1
- package/ConstraintEvaluator.js +246 -353
- package/ConstraintEvaluator.js.map +1 -1
- package/ConstraintEvaluator.test.js +1616 -1438
- package/ConstraintEvaluator.test.js.map +1 -1
- package/ContentSdk.js +83 -90
- package/ContentSdk.js.map +1 -1
- package/DocumentStore.js +47 -59
- package/DocumentStore.js.map +1 -1
- package/DocumentStoreManager.js +17 -16
- package/DocumentStoreManager.js.map +1 -1
- package/EditingSdk.js +87 -121
- package/EditingSdk.js.map +1 -1
- package/ElementFactory.js +126 -174
- package/ElementFactory.js.map +1 -1
- package/ElementFactory.test.js +234 -263
- package/ElementFactory.test.js.map +1 -1
- package/Environment.js +18 -19
- package/Environment.js.map +1 -1
- package/FunctionConverter.js +8 -7
- package/FunctionConverter.js.map +1 -1
- package/HashObject.js +11 -26
- package/HashObject.js.map +1 -1
- package/HotkeyManager.js +40 -47
- package/HotkeyManager.js.map +1 -1
- package/IBindingsUpdater.js +0 -3
- package/IRedirects.js +0 -3
- package/InheritanceProcessor.js +99 -139
- package/InheritanceProcessor.js.map +1 -1
- package/InheritanceProcessor.test.js +178 -179
- package/InheritanceProcessor.test.js.map +1 -1
- package/InheritedValueResolver.js +15 -20
- package/InheritedValueResolver.js.map +1 -1
- package/InputBindingsProcessor.js +187 -307
- package/InputBindingsProcessor.js.map +1 -1
- package/InputsBindingsProcessor.test.js +334 -315
- package/InputsBindingsProcessor.test.js.map +1 -1
- package/InputsUpdater.js +23 -26
- package/InputsUpdater.js.map +1 -1
- package/LiveSdk.js +12 -13
- package/LiveSdk.js.map +1 -1
- package/Logger.js +9 -8
- package/Logger.js.map +1 -1
- package/MouseTracker.js +77 -83
- package/MouseTracker.js.map +1 -1
- package/NullSdk.js +22 -21
- package/NullSdk.js.map +1 -1
- package/PreviewDocument.js +27 -30
- package/PreviewDocument.js.map +1 -1
- package/PreviewSdk.js +16 -17
- package/PreviewSdk.js.map +1 -1
- package/PreviewViewport.js +51 -63
- package/PreviewViewport.js.map +1 -1
- package/ResizeObserver.js +24 -31
- package/ResizeObserver.js.map +1 -1
- package/StylesBindingsProcessor.js +40 -79
- package/StylesBindingsProcessor.js.map +1 -1
- package/StylesUpdater.js +20 -25
- package/StylesUpdater.js.map +1 -1
- package/Theme.js +28 -25
- package/Theme.js.map +1 -1
- package/ViewportManager.js +89 -101
- package/ViewportManager.js.map +1 -1
- package/constants.js +7 -6
- package/constants.js.map +1 -1
- package/createElement.js +5 -6
- package/createElement.js.map +1 -1
- package/createInput.js +85 -143
- package/createInput.js.map +1 -1
- package/createTheme.js +2 -3
- package/createTheme.js.map +1 -1
- package/dataProviders/ApiClient.js +40 -49
- package/dataProviders/ApiClient.js.map +1 -1
- package/dataProviders/DefaultDataProvider.js +56 -58
- package/dataProviders/DefaultDataProvider.js.map +1 -1
- package/dataProviders/GET_PAGE_BY_ID.js +2 -1
- package/dataProviders/GET_PAGE_BY_ID.js.map +1 -1
- package/dataProviders/GET_PAGE_BY_PATH.js +2 -1
- package/dataProviders/GET_PAGE_BY_PATH.js.map +1 -1
- package/dataProviders/LIST_PUBLISHED_PAGES.js +2 -1
- package/dataProviders/LIST_PUBLISHED_PAGES.js.map +1 -1
- package/dataProviders/NullDataProvider.js +21 -20
- package/dataProviders/NullDataProvider.js.map +1 -1
- package/dataProviders/RedirectsProvider.js +24 -27
- package/dataProviders/RedirectsProvider.js.map +1 -1
- package/defaultBreakpoints.js +23 -22
- package/defaultBreakpoints.js.map +1 -1
- package/documentOperations/$addElementReferenceToParent.js +29 -32
- package/documentOperations/$addElementReferenceToParent.js.map +1 -1
- package/documentOperations/AddElement.js +8 -7
- package/documentOperations/AddElement.js.map +1 -1
- package/documentOperations/AddToParent.js +14 -13
- package/documentOperations/AddToParent.js.map +1 -1
- package/documentOperations/IDocumentOperation.js +0 -3
- package/documentOperations/RemoveElement.js +9 -15
- package/documentOperations/RemoveElement.js.map +1 -1
- package/documentOperations/SetGlobalInputBinding.js +23 -22
- package/documentOperations/SetGlobalInputBinding.js.map +1 -1
- package/documentOperations/SetGlobalStyleBinding.js +23 -23
- package/documentOperations/SetGlobalStyleBinding.js.map +1 -1
- package/documentOperations/SetInputBindingOverride.js +30 -29
- package/documentOperations/SetInputBindingOverride.js.map +1 -1
- package/documentOperations/SetStyleBindingOverride.js +30 -31
- package/documentOperations/SetStyleBindingOverride.js.map +1 -1
- package/documentOperations/index.js +9 -8
- package/documentOperations/index.js.map +1 -1
- package/findMatchingAstNode.js +11 -13
- package/findMatchingAstNode.js.map +1 -1
- package/generateElementId.js +2 -1
- package/generateElementId.js.map +1 -1
- package/headersProvider.js +4 -3
- package/headersProvider.js.map +1 -1
- package/index.js +0 -2
- package/jsonPatch.js +5 -9
- package/jsonPatch.js.map +1 -1
- package/messages.js +12 -11
- package/messages.js.map +1 -1
- package/messenger/MessageOrigin.js +12 -11
- package/messenger/MessageOrigin.js.map +1 -1
- package/messenger/Messenger.js +58 -69
- package/messenger/Messenger.js.map +1 -1
- package/messenger/index.js +0 -2
- package/package.json +5 -5
- package/registerComponentGroup.js +5 -6
- package/registerComponentGroup.js.map +1 -1
- package/types/ShorthandCssProperties.js +0 -3
- package/types/WebsiteBuilderTheme.js +0 -3
- package/types.d.ts +3 -0
- package/types.js +0 -3
- package/IBindingsUpdater.js.map +0 -1
- package/IRedirects.js.map +0 -1
- package/documentOperations/IDocumentOperation.js.map +0 -1
- package/index.js.map +0 -1
- package/messenger/index.js.map +0 -1
- package/types/ShorthandCssProperties.js.map +0 -1
- package/types/WebsiteBuilderTheme.js.map +0 -1
- package/types.js.map +0 -1
package/ContentSdk.js
CHANGED
|
@@ -10,97 +10,90 @@ import { Theme } from "./Theme.js";
|
|
|
10
10
|
import { viewportManager } from "./ViewportManager.js";
|
|
11
11
|
import { RedirectsProvider } from "./dataProviders/RedirectsProvider.js";
|
|
12
12
|
class InternalContentSdk {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
13
|
+
constructor(redirectsProvider, liveSdk, editingSdk){
|
|
14
|
+
this.redirectsProvider = redirectsProvider;
|
|
15
|
+
this.activeSdk = editingSdk ?? liveSdk;
|
|
16
|
+
this.editingSdk = editingSdk;
|
|
17
|
+
}
|
|
18
|
+
getEditingSdk() {
|
|
19
|
+
return this.editingSdk;
|
|
20
|
+
}
|
|
21
|
+
async getPage(path) {
|
|
22
|
+
return this.activeSdk.getPage(path);
|
|
23
|
+
}
|
|
24
|
+
listPages(options) {
|
|
25
|
+
return this.activeSdk.listPages(options);
|
|
26
|
+
}
|
|
27
|
+
getAllRedirects() {
|
|
28
|
+
return this.redirectsProvider.getAllRedirects();
|
|
29
|
+
}
|
|
30
|
+
getRedirectByPath(path) {
|
|
31
|
+
return this.redirectsProvider.getRedirectByPath(path);
|
|
32
|
+
}
|
|
33
33
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
isPreviewing() {
|
|
96
|
-
return this.isPreview;
|
|
97
|
-
}
|
|
98
|
-
assertInitialized() {
|
|
99
|
-
if (!this.sdk) {
|
|
100
|
-
throw new Error(`ContentSdk has not been initialized!`);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
34
|
+
class ContentSdk {
|
|
35
|
+
init(config, afterInit) {
|
|
36
|
+
const configHash = JSON.stringify(config);
|
|
37
|
+
if (this.lastConfig && this.lastConfig === configHash) return;
|
|
38
|
+
this.lastConfig = configHash;
|
|
39
|
+
const apiClient = new ApiClient(config.apiHost, config.apiKey, config.apiTenant);
|
|
40
|
+
const dataProvider = new DefaultDataProvider({
|
|
41
|
+
apiClient
|
|
42
|
+
});
|
|
43
|
+
let liveSdk = new LiveSdk(dataProvider);
|
|
44
|
+
if (config.preview && !environment.isEditing()) {
|
|
45
|
+
this.isPreview = true;
|
|
46
|
+
liveSdk = new PreviewSdk(dataProvider, liveSdk);
|
|
47
|
+
}
|
|
48
|
+
const theme = Theme.from(config.theme ?? {});
|
|
49
|
+
if (environment.isClient()) viewportManager.setBreakpoints(theme.breakpoints);
|
|
50
|
+
let editingSdk;
|
|
51
|
+
if (environment.isEditing()) editingSdk = new EditingSdk(liveSdk, theme);
|
|
52
|
+
this.sdk = new InternalContentSdk(new RedirectsProvider(apiClient), liveSdk, editingSdk);
|
|
53
|
+
if ("function" == typeof afterInit) afterInit();
|
|
54
|
+
}
|
|
55
|
+
getEditingSdk() {
|
|
56
|
+
this.assertInitialized();
|
|
57
|
+
return this.sdk.getEditingSdk();
|
|
58
|
+
}
|
|
59
|
+
getPage(path) {
|
|
60
|
+
this.assertInitialized();
|
|
61
|
+
return this.sdk.getPage(path);
|
|
62
|
+
}
|
|
63
|
+
listPages(options) {
|
|
64
|
+
this.assertInitialized();
|
|
65
|
+
return this.sdk.listPages(options);
|
|
66
|
+
}
|
|
67
|
+
async getAllRedirects() {
|
|
68
|
+
this.assertInitialized();
|
|
69
|
+
return this.sdk.getAllRedirects();
|
|
70
|
+
}
|
|
71
|
+
getRedirectByPath(path) {
|
|
72
|
+
this.assertInitialized();
|
|
73
|
+
return this.sdk.getRedirectByPath(path);
|
|
74
|
+
}
|
|
75
|
+
registerComponent(blueprint) {
|
|
76
|
+
this.assertInitialized();
|
|
77
|
+
componentRegistry.register(blueprint);
|
|
78
|
+
}
|
|
79
|
+
resolveElement(params) {
|
|
80
|
+
this.assertInitialized();
|
|
81
|
+
return new ComponentResolver(componentRegistry).resolve(params);
|
|
82
|
+
}
|
|
83
|
+
isEditing() {
|
|
84
|
+
return environment.isEditing();
|
|
85
|
+
}
|
|
86
|
+
isPreviewing() {
|
|
87
|
+
return this.isPreview;
|
|
88
|
+
}
|
|
89
|
+
assertInitialized() {
|
|
90
|
+
if (!this.sdk) throw new Error("ContentSdk has not been initialized!");
|
|
91
|
+
}
|
|
92
|
+
constructor(){
|
|
93
|
+
this.isPreview = false;
|
|
94
|
+
}
|
|
103
95
|
}
|
|
104
|
-
|
|
96
|
+
const contentSdk = new ContentSdk();
|
|
97
|
+
export { ContentSdk, contentSdk };
|
|
105
98
|
|
|
106
99
|
//# sourceMappingURL=ContentSdk.js.map
|
package/ContentSdk.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"ContentSdk.js","sources":["../src/ContentSdk.ts"],"sourcesContent":["import type {\n Component,\n IContentSdk,\n ListPagesOptions,\n ListPagesResult,\n PublicPage,\n PublicRedirect,\n ResolvedComponent\n} from \"~/types.js\";\nimport { environment } from \"./Environment.js\";\nimport { LiveSdk } from \"./LiveSdk.js\";\nimport { EditingSdk } from \"./EditingSdk.js\";\nimport { ComponentResolver, type ResolveElementParams } from \"~/ComponentResolver.js\";\nimport { PreviewSdk } from \"./PreviewSdk.js\";\nimport { componentRegistry } from \"~/ComponentRegistry.js\";\nimport { ApiClient } from \"~/dataProviders/ApiClient.js\";\nimport { DefaultDataProvider } from \"~/dataProviders/DefaultDataProvider.js\";\nimport type { WebsiteBuilderThemeInput } from \"./types/WebsiteBuilderTheme.js\";\nimport { Theme } from \"./Theme.js\";\nimport { viewportManager } from \"./ViewportManager.js\";\nimport type { IRedirects } from \"~/IRedirects.js\";\nimport { RedirectsProvider } from \"~/dataProviders/RedirectsProvider.js\";\n\nexport type ApiConfig = {\n apiKey: string;\n apiHost: string;\n apiTenant: string;\n};\n\nexport type ContentSDKConfig = ApiConfig & {\n preview?: boolean;\n theme?: WebsiteBuilderThemeInput;\n};\n\nclass InternalContentSdk implements IContentSdk, IRedirects {\n private activeSdk: IContentSdk;\n private editingSdk: EditingSdk | undefined;\n private redirectsProvider: IRedirects;\n\n constructor(redirectsProvider: IRedirects, liveSdk: LiveSdk, editingSdk?: EditingSdk) {\n this.redirectsProvider = redirectsProvider;\n this.activeSdk = editingSdk ?? liveSdk;\n this.editingSdk = editingSdk;\n }\n\n getEditingSdk() {\n return this.editingSdk;\n }\n\n async getPage(path: string): Promise<PublicPage | null> {\n return this.activeSdk.getPage(path);\n }\n\n listPages(options?: ListPagesOptions): Promise<ListPagesResult> {\n return this.activeSdk.listPages(options);\n }\n\n getAllRedirects(): Promise<Map<string, PublicRedirect>> {\n return this.redirectsProvider.getAllRedirects();\n }\n\n getRedirectByPath(path: string): Promise<PublicRedirect | undefined> {\n return this.redirectsProvider.getRedirectByPath(path);\n }\n}\n\nexport class ContentSdk implements IContentSdk, IRedirects {\n protected sdk?: InternalContentSdk;\n private isPreview = false;\n private lastConfig: any;\n\n public init(config: ContentSDKConfig, afterInit?: () => void): void {\n const configHash = JSON.stringify(config);\n if (this.lastConfig && this.lastConfig === configHash) {\n return;\n }\n\n this.lastConfig = configHash;\n const apiClient = new ApiClient(config.apiHost, config.apiKey, config.apiTenant);\n\n const dataProvider = new DefaultDataProvider({ apiClient });\n\n let liveSdk: IContentSdk = new LiveSdk(dataProvider);\n\n if (config.preview && !environment.isEditing()) {\n this.isPreview = true;\n liveSdk = new PreviewSdk(dataProvider, liveSdk);\n }\n\n const theme = Theme.from(config.theme ?? {});\n\n if (environment.isClient()) {\n viewportManager.setBreakpoints(theme.breakpoints);\n }\n\n let editingSdk;\n if (environment.isEditing()) {\n editingSdk = new EditingSdk(liveSdk, theme);\n }\n\n this.sdk = new InternalContentSdk(\n new RedirectsProvider(apiClient),\n liveSdk as LiveSdk,\n editingSdk\n );\n\n if (typeof afterInit === \"function\") {\n afterInit();\n }\n }\n\n public getEditingSdk() {\n this.assertInitialized();\n return this.sdk.getEditingSdk();\n }\n\n public getPage(path: string) {\n this.assertInitialized();\n return this.sdk.getPage(path);\n }\n\n public listPages(options?: ListPagesOptions) {\n this.assertInitialized();\n return this.sdk.listPages(options);\n }\n\n public async getAllRedirects() {\n this.assertInitialized();\n return this.sdk.getAllRedirects();\n }\n\n getRedirectByPath(path: string): Promise<PublicRedirect | undefined> {\n this.assertInitialized();\n return this.sdk.getRedirectByPath(path);\n }\n\n registerComponent(blueprint: Component): void {\n this.assertInitialized();\n componentRegistry.register(blueprint);\n }\n\n resolveElement(params: ResolveElementParams): ResolvedComponent[] | null {\n this.assertInitialized();\n return new ComponentResolver(componentRegistry).resolve(params);\n }\n\n isEditing() {\n return environment.isEditing();\n }\n\n isPreviewing() {\n return this.isPreview;\n }\n\n private assertInitialized(): asserts this is this & {\n sdk: IContentSdk;\n } {\n if (!this.sdk) {\n throw new Error(`ContentSdk has not been initialized!`);\n }\n }\n}\n\nexport const contentSdk = new ContentSdk();\n"],"names":["InternalContentSdk","redirectsProvider","liveSdk","editingSdk","path","options","ContentSdk","config","afterInit","configHash","JSON","apiClient","ApiClient","dataProvider","DefaultDataProvider","LiveSdk","environment","PreviewSdk","theme","Theme","viewportManager","EditingSdk","RedirectsProvider","blueprint","componentRegistry","params","ComponentResolver","Error","contentSdk"],"mappings":";;;;;;;;;;;AAkCA,MAAMA;IAKF,YAAYC,iBAA6B,EAAEC,OAAgB,EAAEC,UAAuB,CAAE;QAClF,IAAI,CAAC,iBAAiB,GAAGF;QACzB,IAAI,CAAC,SAAS,GAAGE,cAAcD;QAC/B,IAAI,CAAC,UAAU,GAAGC;IACtB;IAEA,gBAAgB;QACZ,OAAO,IAAI,CAAC,UAAU;IAC1B;IAEA,MAAM,QAAQC,IAAY,EAA8B;QACpD,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAACA;IAClC;IAEA,UAAUC,OAA0B,EAA4B;QAC5D,OAAO,IAAI,CAAC,SAAS,CAAC,SAAS,CAACA;IACpC;IAEA,kBAAwD;QACpD,OAAO,IAAI,CAAC,iBAAiB,CAAC,eAAe;IACjD;IAEA,kBAAkBD,IAAY,EAAuC;QACjE,OAAO,IAAI,CAAC,iBAAiB,CAAC,iBAAiB,CAACA;IACpD;AACJ;AAEO,MAAME;IAKF,KAAKC,MAAwB,EAAEC,SAAsB,EAAQ;QAChE,MAAMC,aAAaC,KAAK,SAAS,CAACH;QAClC,IAAI,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,UAAU,KAAKE,YACvC;QAGJ,IAAI,CAAC,UAAU,GAAGA;QAClB,MAAME,YAAY,IAAIC,UAAUL,OAAO,OAAO,EAAEA,OAAO,MAAM,EAAEA,OAAO,SAAS;QAE/E,MAAMM,eAAe,IAAIC,oBAAoB;YAAEH;QAAU;QAEzD,IAAIT,UAAuB,IAAIa,QAAQF;QAEvC,IAAIN,OAAO,OAAO,IAAI,CAACS,YAAY,SAAS,IAAI;YAC5C,IAAI,CAAC,SAAS,GAAG;YACjBd,UAAU,IAAIe,WAAWJ,cAAcX;QAC3C;QAEA,MAAMgB,QAAQC,MAAM,IAAI,CAACZ,OAAO,KAAK,IAAI,CAAC;QAE1C,IAAIS,YAAY,QAAQ,IACpBI,gBAAgB,cAAc,CAACF,MAAM,WAAW;QAGpD,IAAIf;QACJ,IAAIa,YAAY,SAAS,IACrBb,aAAa,IAAIkB,WAAWnB,SAASgB;QAGzC,IAAI,CAAC,GAAG,GAAG,IAAIlB,mBACX,IAAIsB,kBAAkBX,YACtBT,SACAC;QAGJ,IAAI,AAAqB,cAArB,OAAOK,WACPA;IAER;IAEO,gBAAgB;QACnB,IAAI,CAAC,iBAAiB;QACtB,OAAO,IAAI,CAAC,GAAG,CAAC,aAAa;IACjC;IAEO,QAAQJ,IAAY,EAAE;QACzB,IAAI,CAAC,iBAAiB;QACtB,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAACA;IAC5B;IAEO,UAAUC,OAA0B,EAAE;QACzC,IAAI,CAAC,iBAAiB;QACtB,OAAO,IAAI,CAAC,GAAG,CAAC,SAAS,CAACA;IAC9B;IAEA,MAAa,kBAAkB;QAC3B,IAAI,CAAC,iBAAiB;QACtB,OAAO,IAAI,CAAC,GAAG,CAAC,eAAe;IACnC;IAEA,kBAAkBD,IAAY,EAAuC;QACjE,IAAI,CAAC,iBAAiB;QACtB,OAAO,IAAI,CAAC,GAAG,CAAC,iBAAiB,CAACA;IACtC;IAEA,kBAAkBmB,SAAoB,EAAQ;QAC1C,IAAI,CAAC,iBAAiB;QACtBC,kBAAkB,QAAQ,CAACD;IAC/B;IAEA,eAAeE,MAA4B,EAA8B;QACrE,IAAI,CAAC,iBAAiB;QACtB,OAAO,IAAIC,kBAAkBF,mBAAmB,OAAO,CAACC;IAC5D;IAEA,YAAY;QACR,OAAOT,YAAY,SAAS;IAChC;IAEA,eAAe;QACX,OAAO,IAAI,CAAC,SAAS;IACzB;IAEQ,oBAEN;QACE,IAAI,CAAC,IAAI,CAAC,GAAG,EACT,MAAM,IAAIW,MAAM;IAExB;;aA5FQ,SAAS,GAAG;;AA6FxB;AAEO,MAAMC,aAAa,IAAItB"}
|
package/DocumentStore.js
CHANGED
|
@@ -1,67 +1,55 @@
|
|
|
1
1
|
import { jsonPatch } from "./jsonPatch.js";
|
|
2
|
-
import { makeAutoObservable,
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
setDocument(doc) {
|
|
11
|
-
runInAction(() => {
|
|
12
|
-
if (this.document) {
|
|
13
|
-
Object.assign(this.document, doc);
|
|
14
|
-
} else {
|
|
15
|
-
this.document = observable(doc);
|
|
16
|
-
}
|
|
17
|
-
this.documentReady = true;
|
|
18
|
-
this.readyResolvers.forEach(fn => fn());
|
|
19
|
-
this.readyResolvers = [];
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
updateDocument(cb) {
|
|
23
|
-
runInAction(() => {
|
|
24
|
-
if (this.document) {
|
|
25
|
-
cb(this.document);
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
getDocument() {
|
|
30
|
-
return this.document;
|
|
31
|
-
}
|
|
32
|
-
getElement(id) {
|
|
33
|
-
if (!this.document) {
|
|
34
|
-
return null;
|
|
2
|
+
import { makeAutoObservable, observable, runInAction } from "mobx";
|
|
3
|
+
class DocumentStore {
|
|
4
|
+
constructor(){
|
|
5
|
+
this.document = null;
|
|
6
|
+
this.documentReady = false;
|
|
7
|
+
this.readyResolvers = [];
|
|
8
|
+
makeAutoObservable(this);
|
|
35
9
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
10
|
+
setDocument(doc) {
|
|
11
|
+
runInAction(()=>{
|
|
12
|
+
if (this.document) Object.assign(this.document, doc);
|
|
13
|
+
else this.document = observable(doc);
|
|
14
|
+
this.documentReady = true;
|
|
15
|
+
this.readyResolvers.forEach((fn)=>fn());
|
|
16
|
+
this.readyResolvers = [];
|
|
17
|
+
});
|
|
41
18
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
...patch
|
|
47
|
-
};
|
|
19
|
+
updateDocument(cb) {
|
|
20
|
+
runInAction(()=>{
|
|
21
|
+
if (this.document) cb(this.document);
|
|
22
|
+
});
|
|
48
23
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
24
|
+
getDocument() {
|
|
25
|
+
return this.document;
|
|
26
|
+
}
|
|
27
|
+
getElement(id) {
|
|
28
|
+
if (!this.document) return null;
|
|
29
|
+
return this.document.elements[id];
|
|
30
|
+
}
|
|
31
|
+
updateElement(id, patch) {
|
|
32
|
+
if (!this.document) return;
|
|
33
|
+
const current = this.document.elements[id];
|
|
34
|
+
if (current) this.document.elements[id] = {
|
|
35
|
+
...current,
|
|
36
|
+
...patch
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
applyPatch(patch) {
|
|
40
|
+
runInAction(()=>{
|
|
41
|
+
jsonPatch.applyPatch(this.document, patch, false, true);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
async waitForDocument() {
|
|
45
|
+
if (this.documentReady) return this.document;
|
|
46
|
+
return new Promise((resolve)=>{
|
|
47
|
+
this.readyResolvers.push(()=>{
|
|
48
|
+
resolve(this.document);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
58
51
|
}
|
|
59
|
-
return new Promise(resolve => {
|
|
60
|
-
this.readyResolvers.push(() => {
|
|
61
|
-
resolve(this.document);
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
52
|
}
|
|
53
|
+
export { DocumentStore };
|
|
66
54
|
|
|
67
55
|
//# sourceMappingURL=DocumentStore.js.map
|
package/DocumentStore.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"DocumentStore.js","sources":["../src/DocumentStore.ts"],"sourcesContent":["import { jsonPatch, type JsonPatchOperation } from \"~/jsonPatch.js\";\nimport type { Document } from \"~/types.js\";\nimport { makeAutoObservable, runInAction, observable } from \"mobx\";\n\nexport class DocumentStore<TDocument extends Document = Document> {\n private document: TDocument | null = null;\n private documentReady = false;\n private readyResolvers: (() => void)[] = [];\n\n constructor() {\n makeAutoObservable(this);\n }\n\n setDocument(doc: TDocument) {\n runInAction(() => {\n if (this.document) {\n Object.assign(this.document, doc);\n } else {\n this.document = observable(doc);\n }\n this.documentReady = true;\n this.readyResolvers.forEach(fn => fn());\n this.readyResolvers = [];\n });\n }\n\n updateDocument(cb: (document: TDocument) => void) {\n runInAction(() => {\n if (this.document) {\n cb(this.document);\n }\n });\n }\n\n getDocument() {\n return this.document;\n }\n\n getElement(id: string) {\n if (!this.document) {\n return null;\n }\n\n return this.document.elements[id];\n }\n\n updateElement(id: string, patch: Partial<any>) {\n if (!this.document) {\n return;\n }\n\n const current = this.document.elements[id];\n if (current) {\n this.document.elements[id] = { ...current, ...patch };\n }\n }\n\n applyPatch(patch: JsonPatchOperation[]) {\n runInAction(() => {\n jsonPatch.applyPatch(this.document!, patch, false, true);\n });\n }\n\n async waitForDocument(): Promise<TDocument> {\n if (this.documentReady) {\n return this.document as TDocument;\n }\n\n return new Promise(resolve => {\n this.readyResolvers.push(() => {\n resolve(this.document as TDocument);\n });\n });\n }\n}\n"],"names":["DocumentStore","makeAutoObservable","doc","runInAction","Object","observable","fn","cb","id","patch","current","jsonPatch","Promise","resolve"],"mappings":";;AAIO,MAAMA;IAKT,aAAc;aAJN,QAAQ,GAAqB;aAC7B,aAAa,GAAG;aAChB,cAAc,GAAmB,EAAE;QAGvCC,mBAAmB,IAAI;IAC3B;IAEA,YAAYC,GAAc,EAAE;QACxBC,YAAY;YACR,IAAI,IAAI,CAAC,QAAQ,EACbC,OAAO,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAEF;iBAE7B,IAAI,CAAC,QAAQ,GAAGG,WAAWH;YAE/B,IAAI,CAAC,aAAa,GAAG;YACrB,IAAI,CAAC,cAAc,CAAC,OAAO,CAACI,CAAAA,KAAMA;YAClC,IAAI,CAAC,cAAc,GAAG,EAAE;QAC5B;IACJ;IAEA,eAAeC,EAAiC,EAAE;QAC9CJ,YAAY;YACR,IAAI,IAAI,CAAC,QAAQ,EACbI,GAAG,IAAI,CAAC,QAAQ;QAExB;IACJ;IAEA,cAAc;QACV,OAAO,IAAI,CAAC,QAAQ;IACxB;IAEA,WAAWC,EAAU,EAAE;QACnB,IAAI,CAAC,IAAI,CAAC,QAAQ,EACd,OAAO;QAGX,OAAO,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAACA,GAAG;IACrC;IAEA,cAAcA,EAAU,EAAEC,KAAmB,EAAE;QAC3C,IAAI,CAAC,IAAI,CAAC,QAAQ,EACd;QAGJ,MAAMC,UAAU,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAACF,GAAG;QAC1C,IAAIE,SACA,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAACF,GAAG,GAAG;YAAE,GAAGE,OAAO;YAAE,GAAGD,KAAK;QAAC;IAE5D;IAEA,WAAWA,KAA2B,EAAE;QACpCN,YAAY;YACRQ,UAAU,UAAU,CAAC,IAAI,CAAC,QAAQ,EAAGF,OAAO,OAAO;QACvD;IACJ;IAEA,MAAM,kBAAsC;QACxC,IAAI,IAAI,CAAC,aAAa,EAClB,OAAO,IAAI,CAAC,QAAQ;QAGxB,OAAO,IAAIG,QAAQC,CAAAA;YACf,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC;gBACrBA,QAAQ,IAAI,CAAC,QAAQ;YACzB;QACJ;IACJ;AACJ"}
|
package/DocumentStoreManager.js
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
import { DocumentStore } from "./DocumentStore.js";
|
|
2
2
|
class DocumentStoreManager {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
getStores() {
|
|
4
|
+
return this.stores;
|
|
5
|
+
}
|
|
6
|
+
getStore(id) {
|
|
7
|
+
if (!this.stores.has(id)) this.stores.set(id, new DocumentStore());
|
|
8
|
+
return this.stores.get(id);
|
|
9
|
+
}
|
|
10
|
+
removeStore(id) {
|
|
11
|
+
this.stores.delete(id);
|
|
12
|
+
}
|
|
13
|
+
hasStore(id) {
|
|
14
|
+
return this.stores.has(id);
|
|
15
|
+
}
|
|
16
|
+
constructor(){
|
|
17
|
+
this.stores = new Map();
|
|
10
18
|
}
|
|
11
|
-
return this.stores.get(id);
|
|
12
|
-
}
|
|
13
|
-
removeStore(id) {
|
|
14
|
-
this.stores.delete(id);
|
|
15
|
-
}
|
|
16
|
-
hasStore(id) {
|
|
17
|
-
return this.stores.has(id);
|
|
18
|
-
}
|
|
19
19
|
}
|
|
20
|
-
|
|
20
|
+
const documentStoreManager = new DocumentStoreManager();
|
|
21
|
+
export { documentStoreManager };
|
|
21
22
|
|
|
22
23
|
//# sourceMappingURL=DocumentStoreManager.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"DocumentStoreManager.js","sources":["../src/DocumentStoreManager.ts"],"sourcesContent":["import type { Document } from \"./types.js\";\nimport { DocumentStore } from \"./DocumentStore.js\";\n\nclass DocumentStoreManager {\n private stores = new Map<string, DocumentStore>();\n\n getStores() {\n return this.stores;\n }\n\n getStore<TDocument extends Document>(id: string): DocumentStore<TDocument> {\n if (!this.stores.has(id)) {\n this.stores.set(id, new DocumentStore<TDocument>());\n }\n return this.stores.get(id)! as DocumentStore<TDocument>;\n }\n\n removeStore(id: string) {\n this.stores.delete(id);\n }\n\n hasStore(id: string): boolean {\n return this.stores.has(id);\n }\n}\n\nexport const documentStoreManager = new DocumentStoreManager();\n"],"names":["DocumentStoreManager","id","DocumentStore","Map","documentStoreManager"],"mappings":";AAGA,MAAMA;IAGF,YAAY;QACR,OAAO,IAAI,CAAC,MAAM;IACtB;IAEA,SAAqCC,EAAU,EAA4B;QACvE,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAACA,KACjB,IAAI,CAAC,MAAM,CAAC,GAAG,CAACA,IAAI,IAAIC;QAE5B,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAACD;IAC3B;IAEA,YAAYA,EAAU,EAAE;QACpB,IAAI,CAAC,MAAM,CAAC,MAAM,CAACA;IACvB;IAEA,SAASA,EAAU,EAAW;QAC1B,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAACA;IAC3B;;aAnBQ,MAAM,GAAG,IAAIE;;AAoBzB;AAEO,MAAMC,uBAAuB,IAAIJ"}
|