@servicetitan/dte-unlayer 0.21.0 → 0.23.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/tools-api.js DELETED
@@ -1,156 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { loadScript } from './loadScript';
11
- const dummyStore = {
12
- renderHtml() {
13
- return '';
14
- },
15
- sendData() { },
16
- getTool() {
17
- return undefined;
18
- },
19
- };
20
- const baseName = 'https://unpkg.servicetitan.com/@servicetitan/dte-tools';
21
- const baseTag = 'prod2';
22
- export class UnlayerToolsApi {
23
- constructor() {
24
- Object.defineProperty(this, "dataInternal", {
25
- enumerable: true,
26
- configurable: true,
27
- writable: true,
28
- value: void 0
29
- });
30
- Object.defineProperty(this, "loaded", {
31
- enumerable: true,
32
- configurable: true,
33
- writable: true,
34
- value: new Set()
35
- });
36
- Object.defineProperty(this, "schemas", {
37
- enumerable: true,
38
- configurable: true,
39
- writable: true,
40
- value: void 0
41
- });
42
- }
43
- get dteStore() {
44
- var _a;
45
- return (_a = window.dteStore) !== null && _a !== void 0 ? _a : dummyStore;
46
- }
47
- get data() {
48
- return this.dataInternal;
49
- }
50
- init(opts) {
51
- var _a, _b;
52
- return __awaiter(this, void 0, void 0, function* () {
53
- const url = (_a = opts === null || opts === void 0 ? void 0 : opts.url) !== null && _a !== void 0 ? _a : baseName;
54
- const tag = (_b = opts === null || opts === void 0 ? void 0 : opts.tag) !== null && _b !== void 0 ? _b : baseTag;
55
- const initialUrl = `${url}${tag ? '@' + tag : ''}`;
56
- return Promise.all([
57
- fetch(`${initialUrl}/data.json`).then(response => response
58
- .json()
59
- .then(data => (Object.assign(Object.assign({}, data), { packageUrl: response.url.replace('/data.json', '') })))),
60
- fetch(`${initialUrl}/custom.css`).then(response => response.text()),
61
- ])
62
- .then(([{ core, coreTools, packageUrl, tools }, customCSS]) => ({
63
- customTools: tools,
64
- packageUrl,
65
- customCSS,
66
- core: core !== null && core !== void 0 ? core : ['/core.bundle.js'],
67
- coreTools: coreTools !== null && coreTools !== void 0 ? coreTools : [],
68
- tag,
69
- }))
70
- .then(data => {
71
- this.dataInternal = data;
72
- });
73
- });
74
- }
75
- clean() {
76
- this.dataInternal = undefined;
77
- this.loaded = new Set();
78
- this.schemas = undefined;
79
- }
80
- loadSchemas() {
81
- return __awaiter(this, void 0, void 0, function* () {
82
- if (this.schemas) {
83
- return this.schemas;
84
- }
85
- return fetch(`${this.data.packageUrl}/schemas.json`)
86
- .then(response => response.json())
87
- .then(schemas => {
88
- this.schemas = schemas;
89
- return schemas;
90
- });
91
- });
92
- }
93
- preloadCore() {
94
- return __awaiter(this, void 0, void 0, function* () {
95
- if (this.loaded.has('_core') || !this.dataInternal) {
96
- return;
97
- }
98
- this.loaded.add('_core');
99
- yield Promise.all(this.data.core.map(c => loadScript(`${this.data.packageUrl}${c}`)));
100
- });
101
- }
102
- preloadCoreTools() {
103
- return __awaiter(this, void 0, void 0, function* () {
104
- if (this.loaded.has('_coreTools') || !this.dataInternal) {
105
- return;
106
- }
107
- this.loaded.add('_coreTools');
108
- yield Promise.all(this.data.coreTools.map(c => loadScript(`${this.data.packageUrl}${c}`)));
109
- });
110
- }
111
- preloadCustomTools(tools) {
112
- return __awaiter(this, void 0, void 0, function* () {
113
- if (!this.dataInternal) {
114
- return;
115
- }
116
- const toolsMap = this.data.customTools.reduce((out, t) => {
117
- out[t.key] = t.path;
118
- return out;
119
- }, {});
120
- yield this.preloadCore();
121
- yield Promise.all(tools
122
- .filter(t => !!toolsMap[t] && !this.loaded.has(t))
123
- .map(t => {
124
- this.loaded.add(t);
125
- return loadScript(this.data.packageUrl + '/' + toolsMap[t]).catch(() => null);
126
- }));
127
- });
128
- }
129
- getCustomToolModel(key) {
130
- var _a;
131
- const dteTool = this.dteStore.getTool(key);
132
- if (!dteTool) {
133
- return {};
134
- }
135
- try {
136
- return (_a = dteTool.getModel()) !== null && _a !== void 0 ? _a : {};
137
- }
138
- catch (_b) {
139
- return {};
140
- }
141
- }
142
- getCustomToolDataSources(tool) {
143
- var _a;
144
- const dteTool = this.dteStore.getTool(tool.slug);
145
- if (!dteTool) {
146
- return [];
147
- }
148
- try {
149
- return (_a = dteTool.dataSources(tool.values)) !== null && _a !== void 0 ? _a : [];
150
- }
151
- catch (_b) {
152
- return [];
153
- }
154
- }
155
- }
156
- //# sourceMappingURL=tools-api.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tools-api.js","sourceRoot":"","sources":["../src/tools-api.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAI1C,MAAM,UAAU,GAAiB;IAC7B,UAAU;QACN,OAAO,EAAE,CAAC;IACd,CAAC;IACD,QAAQ,KAAI,CAAC;IACb,OAAO;QACH,OAAO,SAAS,CAAC;IACrB,CAAC;CACJ,CAAC;AAEF,MAAM,QAAQ,GAAG,wDAAwD,CAAC;AAC1E,MAAM,OAAO,GAAG,OAAO,CAAC;AAExB,MAAM,OAAO,eAAe;IAA5B;QACI;;;;;WAA0C;QAC1C;;;;mBAAiB,IAAI,GAAG,EAAU;WAAC;QACnC;;;;;WAAsC;IA4H1C,CAAC;IA1HG,IAAY,QAAQ;;QAChB,OAAO,MAAC,MAAc,CAAC,QAAQ,mCAAI,UAAU,CAAC;IAClD,CAAC;IAED,IAAI,IAAI;QACJ,OAAO,IAAI,CAAC,YAAa,CAAC;IAC9B,CAAC;IAEK,IAAI,CAAC,IAAqC;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O,EAAE,CAAC;SACb;IACL,CAAC;IAED,wBAAwB,CAAC,IAAuB;;QAC5C,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEjD,IAAI,CAAC,OAAO,EAAE;YACV,OAAO,EAAE,CAAC;SACb;QAED,IAAI;YACA,OAAO,MAAA,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,mCAAI,EAAE,CAAC;SACjD;QAAC,WAAM;YACJ,OAAO,EAAE,CAAC;SACb;IACL,CAAC;CACJ"}
package/src/tools-api.ts DELETED
@@ -1,145 +0,0 @@
1
- import { loadScript } from './loadScript';
2
- import { UnlayerStore } from './shared/tools';
3
- import { UnlayerDesignTool, UnlayerPackageData } from './unlayer-interface';
4
-
5
- const dummyStore: UnlayerStore = {
6
- renderHtml() {
7
- return '';
8
- },
9
- sendData() {},
10
- getTool() {
11
- return undefined;
12
- },
13
- };
14
-
15
- const baseName = 'https://unpkg.servicetitan.com/@servicetitan/dte-tools';
16
- const baseTag = 'prod2';
17
-
18
- export class UnlayerToolsApi {
19
- private dataInternal?: UnlayerPackageData;
20
- private loaded = new Set<string>();
21
- private schemas?: Record<string, any>;
22
-
23
- private get dteStore(): UnlayerStore {
24
- return (window as any).dteStore ?? dummyStore;
25
- }
26
-
27
- get data() {
28
- return this.dataInternal!;
29
- }
30
-
31
- async init(opts?: { url?: string; tag?: string }) {
32
- const url = opts?.url ?? baseName;
33
- const tag = opts?.tag ?? baseTag;
34
-
35
- const initialUrl = `${url}${tag ? '@' + tag : ''}`;
36
-
37
- return Promise.all([
38
- fetch(`${initialUrl}/data.json`).then(response =>
39
- response
40
- .json()
41
- .then(data => ({ ...data, packageUrl: response.url.replace('/data.json', '') }))
42
- ),
43
- fetch(`${initialUrl}/custom.css`).then(response => response.text()),
44
- ])
45
- .then(([{ core, coreTools, packageUrl, tools }, customCSS]) => ({
46
- customTools: tools,
47
- packageUrl,
48
- customCSS,
49
- core: core ?? ['/core.bundle.js'],
50
- coreTools: coreTools ?? [],
51
- tag,
52
- }))
53
- .then(data => {
54
- this.dataInternal = data;
55
- });
56
- }
57
-
58
- clean() {
59
- this.dataInternal = undefined;
60
- this.loaded = new Set();
61
- this.schemas = undefined;
62
- }
63
-
64
- async loadSchemas(): Promise<Record<string, any>> {
65
- if (this.schemas) {
66
- return this.schemas;
67
- }
68
-
69
- return fetch(`${this.data.packageUrl}/schemas.json`)
70
- .then(response => response.json())
71
- .then(schemas => {
72
- this.schemas = schemas;
73
-
74
- return schemas;
75
- });
76
- }
77
-
78
- async preloadCore() {
79
- if (this.loaded.has('_core') || !this.dataInternal) {
80
- return;
81
- }
82
- this.loaded.add('_core');
83
-
84
- await Promise.all(this.data.core.map(c => loadScript(`${this.data.packageUrl}${c}`)));
85
- }
86
-
87
- async preloadCoreTools() {
88
- if (this.loaded.has('_coreTools') || !this.dataInternal) {
89
- return;
90
- }
91
- this.loaded.add('_coreTools');
92
-
93
- await Promise.all(this.data.coreTools.map(c => loadScript(`${this.data.packageUrl}${c}`)));
94
- }
95
-
96
- async preloadCustomTools(tools: string[]) {
97
- if (!this.dataInternal) {
98
- return;
99
- }
100
- const toolsMap = this.data.customTools.reduce((out, t) => {
101
- out[t.key] = t.path;
102
-
103
- return out;
104
- }, {} as Record<string, string>);
105
-
106
- await this.preloadCore();
107
-
108
- await Promise.all(
109
- tools
110
- .filter(t => !!toolsMap[t] && !this.loaded.has(t))
111
- .map(t => {
112
- this.loaded.add(t);
113
- return loadScript(this.data.packageUrl + '/' + toolsMap[t]).catch(() => null);
114
- })
115
- );
116
- }
117
-
118
- getCustomToolModel(key: string): object {
119
- const dteTool = this.dteStore.getTool(key);
120
-
121
- if (!dteTool) {
122
- return {};
123
- }
124
-
125
- try {
126
- return dteTool.getModel() ?? {};
127
- } catch {
128
- return {};
129
- }
130
- }
131
-
132
- getCustomToolDataSources(tool: UnlayerDesignTool): string[] {
133
- const dteTool = this.dteStore.getTool(tool.slug);
134
-
135
- if (!dteTool) {
136
- return [];
137
- }
138
-
139
- try {
140
- return dteTool.dataSources(tool.values) ?? [];
141
- } catch {
142
- return [];
143
- }
144
- }
145
- }