@memberjunction/react-runtime 2.70.0 → 2.72.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.
Files changed (32) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +24 -0
  3. package/dist/index.d.ts +5 -0
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +17 -1
  6. package/dist/utilities/component-error-analyzer.d.ts +20 -0
  7. package/dist/utilities/component-error-analyzer.d.ts.map +1 -0
  8. package/dist/utilities/component-error-analyzer.js +204 -0
  9. package/dist/utilities/component-styles.d.ts +4 -0
  10. package/dist/utilities/component-styles.d.ts.map +1 -0
  11. package/dist/utilities/component-styles.js +97 -0
  12. package/dist/utilities/index.d.ts +6 -0
  13. package/dist/utilities/index.d.ts.map +1 -0
  14. package/dist/utilities/index.js +21 -0
  15. package/dist/utilities/library-loader.d.ts +33 -0
  16. package/dist/utilities/library-loader.d.ts.map +1 -0
  17. package/dist/utilities/library-loader.js +193 -0
  18. package/dist/utilities/runtime-utilities.d.ts +10 -0
  19. package/dist/utilities/runtime-utilities.d.ts.map +1 -0
  20. package/dist/utilities/runtime-utilities.js +92 -0
  21. package/dist/utilities/standard-libraries.d.ts +27 -0
  22. package/dist/utilities/standard-libraries.d.ts.map +1 -0
  23. package/dist/utilities/standard-libraries.js +55 -0
  24. package/package.json +4 -1
  25. package/src/index.ts +31 -0
  26. package/src/utilities/component-error-analyzer.ts +315 -0
  27. package/src/utilities/component-styles.ts +121 -0
  28. package/src/utilities/index.ts +10 -0
  29. package/src/utilities/library-loader.ts +307 -0
  30. package/src/utilities/runtime-utilities.ts +122 -0
  31. package/src/utilities/standard-libraries.ts +97 -0
  32. package/tsconfig.tsbuildinfo +1 -1
@@ -0,0 +1,193 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LibraryLoader = void 0;
4
+ const standard_libraries_1 = require("./standard-libraries");
5
+ class LibraryLoader {
6
+ static async loadAllLibraries() {
7
+ return this.loadLibraries({
8
+ loadCore: true,
9
+ loadUI: true,
10
+ loadCSS: true
11
+ });
12
+ }
13
+ static async loadLibraries(options) {
14
+ const { loadCore = true, loadUI = true, loadCSS = true, customLibraries = [] } = options;
15
+ const [React, ReactDOM, Babel] = await Promise.all([
16
+ this.loadScript(standard_libraries_1.STANDARD_LIBRARY_URLS.REACT, 'React'),
17
+ this.loadScript(standard_libraries_1.STANDARD_LIBRARY_URLS.REACT_DOM, 'ReactDOM'),
18
+ this.loadScript(standard_libraries_1.STANDARD_LIBRARY_URLS.BABEL, 'Babel')
19
+ ]);
20
+ if (loadCSS) {
21
+ (0, standard_libraries_1.getCSSUrls)().forEach(url => this.loadCSS(url));
22
+ }
23
+ const libraryPromises = [];
24
+ const libraryNames = [];
25
+ if (loadCore) {
26
+ const coreUrls = (0, standard_libraries_1.getCoreLibraryUrls)();
27
+ coreUrls.forEach(url => {
28
+ const name = this.getLibraryNameFromUrl(url);
29
+ libraryNames.push(name);
30
+ libraryPromises.push(this.loadScript(url, name));
31
+ });
32
+ }
33
+ if (loadUI) {
34
+ const uiUrls = (0, standard_libraries_1.getUILibraryUrls)();
35
+ uiUrls.forEach(url => {
36
+ const name = this.getLibraryNameFromUrl(url);
37
+ libraryNames.push(name);
38
+ libraryPromises.push(this.loadScript(url, name));
39
+ });
40
+ }
41
+ customLibraries.forEach(({ url, globalName }) => {
42
+ libraryNames.push(globalName);
43
+ libraryPromises.push(this.loadScript(url, globalName));
44
+ });
45
+ const loadedLibraries = await Promise.all(libraryPromises);
46
+ const libraries = {
47
+ _: undefined
48
+ };
49
+ libraryNames.forEach((name, index) => {
50
+ if (name === '_') {
51
+ libraries._ = loadedLibraries[index];
52
+ }
53
+ else {
54
+ libraries[name] = loadedLibraries[index];
55
+ }
56
+ });
57
+ if (!libraries._)
58
+ libraries._ = window._;
59
+ if (!libraries.d3)
60
+ libraries.d3 = window.d3;
61
+ if (!libraries.Chart)
62
+ libraries.Chart = window.Chart;
63
+ if (!libraries.dayjs)
64
+ libraries.dayjs = window.dayjs;
65
+ if (!libraries.antd)
66
+ libraries.antd = window.antd;
67
+ if (!libraries.ReactBootstrap)
68
+ libraries.ReactBootstrap = window.ReactBootstrap;
69
+ return {
70
+ React,
71
+ ReactDOM,
72
+ Babel,
73
+ libraries
74
+ };
75
+ }
76
+ static async loadScript(url, globalName) {
77
+ const existing = this.loadedResources.get(url);
78
+ if (existing) {
79
+ return existing.promise;
80
+ }
81
+ const promise = new Promise((resolve, reject) => {
82
+ const existingGlobal = window[globalName];
83
+ if (existingGlobal) {
84
+ resolve(existingGlobal);
85
+ return;
86
+ }
87
+ const existingScript = document.querySelector(`script[src="${url}"]`);
88
+ if (existingScript) {
89
+ this.waitForScriptLoad(existingScript, globalName, resolve, reject);
90
+ return;
91
+ }
92
+ const script = document.createElement('script');
93
+ script.src = url;
94
+ script.async = true;
95
+ script.crossOrigin = 'anonymous';
96
+ script.onload = () => {
97
+ const global = window[globalName];
98
+ if (global) {
99
+ resolve(global);
100
+ }
101
+ else {
102
+ setTimeout(() => {
103
+ const delayedGlobal = window[globalName];
104
+ if (delayedGlobal) {
105
+ resolve(delayedGlobal);
106
+ }
107
+ else {
108
+ reject(new Error(`${globalName} not found after script load`));
109
+ }
110
+ }, 100);
111
+ }
112
+ };
113
+ script.onerror = () => {
114
+ reject(new Error(`Failed to load script: ${url}`));
115
+ };
116
+ document.head.appendChild(script);
117
+ });
118
+ this.loadedResources.set(url, {
119
+ element: document.querySelector(`script[src="${url}"]`),
120
+ promise
121
+ });
122
+ return promise;
123
+ }
124
+ static loadCSS(url) {
125
+ if (this.loadedResources.has(url)) {
126
+ return;
127
+ }
128
+ const existingLink = document.querySelector(`link[href="${url}"]`);
129
+ if (existingLink) {
130
+ return;
131
+ }
132
+ const link = document.createElement('link');
133
+ link.rel = 'stylesheet';
134
+ link.href = url;
135
+ document.head.appendChild(link);
136
+ this.loadedResources.set(url, {
137
+ element: link,
138
+ promise: Promise.resolve()
139
+ });
140
+ }
141
+ static waitForScriptLoad(script, globalName, resolve, reject) {
142
+ const checkGlobal = () => {
143
+ const global = window[globalName];
144
+ if (global) {
145
+ resolve(global);
146
+ }
147
+ else {
148
+ setTimeout(() => {
149
+ const delayedGlobal = window[globalName];
150
+ if (delayedGlobal) {
151
+ resolve(delayedGlobal);
152
+ }
153
+ else {
154
+ reject(new Error(`${globalName} not found after script load`));
155
+ }
156
+ }, 100);
157
+ }
158
+ };
159
+ if (script.complete || script.readyState === 'complete') {
160
+ checkGlobal();
161
+ return;
162
+ }
163
+ const loadHandler = () => {
164
+ script.removeEventListener('load', loadHandler);
165
+ checkGlobal();
166
+ };
167
+ script.addEventListener('load', loadHandler);
168
+ }
169
+ static getLibraryNameFromUrl(url) {
170
+ if (url.includes('lodash'))
171
+ return '_';
172
+ if (url.includes('d3'))
173
+ return 'd3';
174
+ if (url.includes('Chart.js') || url.includes('chart'))
175
+ return 'Chart';
176
+ if (url.includes('dayjs'))
177
+ return 'dayjs';
178
+ if (url.includes('antd'))
179
+ return 'antd';
180
+ if (url.includes('react-bootstrap'))
181
+ return 'ReactBootstrap';
182
+ const match = url.match(/\/([^\/]+)(?:\.min)?\.js$/);
183
+ return match ? match[1] : 'unknown';
184
+ }
185
+ static getLoadedResources() {
186
+ return this.loadedResources;
187
+ }
188
+ static clearCache() {
189
+ this.loadedResources.clear();
190
+ }
191
+ }
192
+ exports.LibraryLoader = LibraryLoader;
193
+ LibraryLoader.loadedResources = new Map();
@@ -0,0 +1,10 @@
1
+ import { ComponentUtilities } from '@memberjunction/interactive-component-types';
2
+ export declare class RuntimeUtilities {
3
+ buildUtilities(): ComponentUtilities;
4
+ private SetupUtilities;
5
+ private CreateSimpleMetadata;
6
+ private CreateSimpleRunQuery;
7
+ private CreateSimpleRunView;
8
+ }
9
+ export declare function createRuntimeUtilities(): RuntimeUtilities;
10
+ //# sourceMappingURL=runtime-utilities.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-utilities.d.ts","sourceRoot":"","sources":["../../src/utilities/runtime-utilities.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,kBAAkB,EAAiD,MAAM,6CAA6C,CAAC;AAOhI,qBACa,gBAAgB;IAKpB,cAAc,IAAI,kBAAkB;IAQ3C,OAAO,CAAC,cAAc;IAWtB,OAAO,CAAC,oBAAoB;IAS5B,OAAO,CAAC,oBAAoB;IAe5B,OAAO,CAAC,mBAAmB;CAwB5B;AAOD,wBAAgB,sBAAsB,IAAI,gBAAgB,CAmBzD"}
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.createRuntimeUtilities = exports.RuntimeUtilities = void 0;
10
+ const core_1 = require("@memberjunction/core");
11
+ const global_1 = require("@memberjunction/global");
12
+ let RuntimeUtilities = class RuntimeUtilities {
13
+ buildUtilities() {
14
+ const md = new core_1.Metadata();
15
+ return this.SetupUtilities(md);
16
+ }
17
+ SetupUtilities(md) {
18
+ const rv = new core_1.RunView();
19
+ const rq = new core_1.RunQuery();
20
+ const u = {
21
+ md: this.CreateSimpleMetadata(md),
22
+ rv: this.CreateSimpleRunView(rv),
23
+ rq: this.CreateSimpleRunQuery(rq)
24
+ };
25
+ return u;
26
+ }
27
+ CreateSimpleMetadata(md) {
28
+ return {
29
+ Entities: md.Entities,
30
+ GetEntityObject: (entityName) => {
31
+ return md.GetEntityObject(entityName);
32
+ }
33
+ };
34
+ }
35
+ CreateSimpleRunQuery(rq) {
36
+ return {
37
+ RunQuery: async (params) => {
38
+ try {
39
+ const result = await rq.RunQuery(params);
40
+ return result;
41
+ }
42
+ catch (error) {
43
+ (0, core_1.LogError)(error);
44
+ throw error;
45
+ }
46
+ }
47
+ };
48
+ }
49
+ CreateSimpleRunView(rv) {
50
+ return {
51
+ RunView: async (params) => {
52
+ try {
53
+ const result = await rv.RunView(params);
54
+ return result;
55
+ }
56
+ catch (error) {
57
+ (0, core_1.LogError)(error);
58
+ throw error;
59
+ }
60
+ },
61
+ RunViews: async (params) => {
62
+ try {
63
+ const results = await rv.RunViews(params);
64
+ return results;
65
+ }
66
+ catch (error) {
67
+ (0, core_1.LogError)(error);
68
+ throw error;
69
+ }
70
+ }
71
+ };
72
+ }
73
+ };
74
+ exports.RuntimeUtilities = RuntimeUtilities;
75
+ exports.RuntimeUtilities = RuntimeUtilities = __decorate([
76
+ (0, global_1.RegisterClass)(RuntimeUtilities, 'RuntimeUtilities')
77
+ ], RuntimeUtilities);
78
+ function createRuntimeUtilities() {
79
+ if (typeof window === 'undefined') {
80
+ try {
81
+ const obj = global_1.MJGlobal.Instance.ClassFactory.CreateInstance(RuntimeUtilities);
82
+ if (!obj) {
83
+ throw new Error('Failed to create RuntimeUtilities instance');
84
+ }
85
+ return obj;
86
+ }
87
+ catch (e) {
88
+ }
89
+ }
90
+ return new RuntimeUtilities();
91
+ }
92
+ exports.createRuntimeUtilities = createRuntimeUtilities;
@@ -0,0 +1,27 @@
1
+ export declare const STANDARD_LIBRARY_URLS: {
2
+ REACT: string;
3
+ REACT_DOM: string;
4
+ BABEL: string;
5
+ D3: string;
6
+ CHART_JS: string;
7
+ LODASH: string;
8
+ DAYJS: string;
9
+ ANTD: string;
10
+ REACT_BOOTSTRAP: string;
11
+ ANTD_CSS: string;
12
+ BOOTSTRAP_CSS: string;
13
+ };
14
+ export interface StandardLibraries {
15
+ _: any;
16
+ d3?: any;
17
+ Chart?: any;
18
+ dayjs?: any;
19
+ antd?: any;
20
+ ReactBootstrap?: any;
21
+ [key: string]: any;
22
+ }
23
+ export declare function getCoreLibraryUrls(): string[];
24
+ export declare function getUILibraryUrls(): string[];
25
+ export declare function getCSSUrls(): string[];
26
+ export declare function createStandardLibraries(): StandardLibraries;
27
+ //# sourceMappingURL=standard-libraries.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"standard-libraries.d.ts","sourceRoot":"","sources":["../../src/utilities/standard-libraries.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,qBAAqB;;;;;;;;;;;;CAqBjC,CAAC;AAKF,MAAM,WAAW,iBAAiB;IAChC,CAAC,EAAE,GAAG,CAAC;IACP,EAAE,CAAC,EAAE,GAAG,CAAC;IACT,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,cAAc,CAAC,EAAE,GAAG,CAAC;IACrB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAKD,wBAAgB,kBAAkB,IAAI,MAAM,EAAE,CAO7C;AAKD,wBAAgB,gBAAgB,IAAI,MAAM,EAAE,CAK3C;AAKD,wBAAgB,UAAU,IAAI,MAAM,EAAE,CAKrC;AAMD,wBAAgB,uBAAuB,IAAI,iBAAiB,CAgB3D"}
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createStandardLibraries = exports.getCSSUrls = exports.getUILibraryUrls = exports.getCoreLibraryUrls = exports.STANDARD_LIBRARY_URLS = void 0;
4
+ exports.STANDARD_LIBRARY_URLS = {
5
+ REACT: 'https://unpkg.com/react@18/umd/react.development.js',
6
+ REACT_DOM: 'https://unpkg.com/react-dom@18/umd/react-dom.development.js',
7
+ BABEL: 'https://unpkg.com/@babel/standalone/babel.min.js',
8
+ D3: 'https://cdnjs.cloudflare.com/ajax/libs/d3/7.8.5/d3.min.js',
9
+ CHART_JS: 'https://cdnjs.cloudflare.com/ajax/libs/Chart.js/4.4.0/chart.umd.js',
10
+ LODASH: 'https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js',
11
+ DAYJS: 'https://unpkg.com/dayjs@1.11.10/dayjs.min.js',
12
+ ANTD: 'https://unpkg.com/antd@5.11.5/dist/antd.min.js',
13
+ REACT_BOOTSTRAP: 'https://unpkg.com/react-bootstrap@2.9.1/dist/react-bootstrap.min.js',
14
+ ANTD_CSS: 'https://unpkg.com/antd@5.11.5/dist/reset.css',
15
+ BOOTSTRAP_CSS: 'https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css'
16
+ };
17
+ function getCoreLibraryUrls() {
18
+ return [
19
+ exports.STANDARD_LIBRARY_URLS.LODASH,
20
+ exports.STANDARD_LIBRARY_URLS.D3,
21
+ exports.STANDARD_LIBRARY_URLS.CHART_JS,
22
+ exports.STANDARD_LIBRARY_URLS.DAYJS
23
+ ];
24
+ }
25
+ exports.getCoreLibraryUrls = getCoreLibraryUrls;
26
+ function getUILibraryUrls() {
27
+ return [
28
+ exports.STANDARD_LIBRARY_URLS.ANTD,
29
+ exports.STANDARD_LIBRARY_URLS.REACT_BOOTSTRAP
30
+ ];
31
+ }
32
+ exports.getUILibraryUrls = getUILibraryUrls;
33
+ function getCSSUrls() {
34
+ return [
35
+ exports.STANDARD_LIBRARY_URLS.ANTD_CSS,
36
+ exports.STANDARD_LIBRARY_URLS.BOOTSTRAP_CSS
37
+ ];
38
+ }
39
+ exports.getCSSUrls = getCSSUrls;
40
+ function createStandardLibraries() {
41
+ if (typeof window === 'undefined') {
42
+ return {
43
+ _: undefined
44
+ };
45
+ }
46
+ return {
47
+ _: window._,
48
+ d3: window.d3,
49
+ Chart: window.Chart,
50
+ dayjs: window.dayjs,
51
+ antd: window.antd,
52
+ ReactBootstrap: window.ReactBootstrap
53
+ };
54
+ }
55
+ exports.createStandardLibraries = createStandardLibraries;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@memberjunction/react-runtime",
3
- "version": "2.70.0",
3
+ "version": "2.72.0",
4
4
  "description": "Platform-agnostic React component runtime for MemberJunction. Provides core compilation, registry, and execution capabilities for React components in any JavaScript environment.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -25,6 +25,9 @@
25
25
  },
26
26
  "homepage": "https://github.com/MemberJunction/MJ#readme",
27
27
  "dependencies": {
28
+ "@memberjunction/core": "2.72.0",
29
+ "@memberjunction/global": "2.72.0",
30
+ "@memberjunction/interactive-component-types": "2.72.0",
28
31
  "@babel/standalone": "^7.23.5"
29
32
  },
30
33
  "devDependencies": {
package/src/index.ts CHANGED
@@ -74,6 +74,37 @@ export {
74
74
  HierarchyRegistrationOptions
75
75
  } from './runtime';
76
76
 
77
+ // Export utilities
78
+ export {
79
+ RuntimeUtilities,
80
+ createRuntimeUtilities
81
+ } from './utilities/runtime-utilities';
82
+
83
+ export {
84
+ SetupStyles,
85
+ createDefaultComponentStyles
86
+ } from './utilities/component-styles';
87
+
88
+ export {
89
+ STANDARD_LIBRARY_URLS,
90
+ StandardLibraries,
91
+ getCoreLibraryUrls,
92
+ getUILibraryUrls,
93
+ getCSSUrls,
94
+ createStandardLibraries
95
+ } from './utilities/standard-libraries';
96
+
97
+ export {
98
+ LibraryLoader,
99
+ LibraryLoadOptions,
100
+ LibraryLoadResult
101
+ } from './utilities/library-loader';
102
+
103
+ export {
104
+ ComponentErrorAnalyzer,
105
+ FailedComponentInfo
106
+ } from './utilities/component-error-analyzer';
107
+
77
108
  // Version information
78
109
  export const VERSION = '2.69.1';
79
110