@sap-ux/preview-middleware 0.16.26 → 0.16.28

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.
@@ -101,9 +101,10 @@ export declare function addApp(templateConfig: TemplateConfig, manifest: Partial
101
101
  *
102
102
  * @param config FLP configuration
103
103
  * @param manifest application manifest
104
+ * @param resources additional resources
104
105
  * @returns configuration object for the sandbox.html template
105
106
  */
106
- export declare function createFlpTemplateConfig(config: FlpConfig, manifest: Partial<Manifest>): TemplateConfig;
107
+ export declare function createFlpTemplateConfig(config: FlpConfig, manifest: Partial<Manifest>, resources?: Record<string, string>): TemplateConfig;
107
108
  /**
108
109
  * Creates the configuration object for the test template.
109
110
  *
@@ -196,9 +196,10 @@ async function getI18nTextFromProperty(projectRoot, propertyValue, logger) {
196
196
  *
197
197
  * @param config FLP configuration
198
198
  * @param manifest application manifest
199
+ * @param resources additional resources
199
200
  * @returns configuration object for the sandbox.html template
200
201
  */
201
- function createFlpTemplateConfig(config, manifest) {
202
+ function createFlpTemplateConfig(config, manifest, resources = {}) {
202
203
  const flex = getFlexSettings();
203
204
  const supportedThemes = manifest['sap.ui5']?.supportedThemes ?? [exports.DEFAULT_THEME];
204
205
  const ui5Theme = config.theme ?? (supportedThemes.includes(exports.DEFAULT_THEME) ? exports.DEFAULT_THEME : supportedThemes[0]);
@@ -213,6 +214,7 @@ function createFlpTemplateConfig(config, manifest) {
213
214
  theme: ui5Theme,
214
215
  flex,
215
216
  resources: {
217
+ ...resources,
216
218
  [exports.PREVIEW_URL.client.ns]: exports.PREVIEW_URL.client.url
217
219
  },
218
220
  bootstrapOptions: ''
package/dist/base/flp.js CHANGED
@@ -72,7 +72,7 @@ class FlpSandbox {
72
72
  this.createFlexHandler();
73
73
  this.config.libs ??= await this.hasLocateReuseLibsScript();
74
74
  const id = manifest['sap.app'].id;
75
- this.templateConfig = (0, config_1.createFlpTemplateConfig)(this.config, manifest);
75
+ this.templateConfig = (0, config_1.createFlpTemplateConfig)(this.config, manifest, resources);
76
76
  await (0, config_1.addApp)(this.templateConfig, manifest, {
77
77
  componentId,
78
78
  target: resources[componentId ?? id] ?? this.templateConfig.basePath,
@@ -33,7 +33,7 @@ sap.ui.define([
33
33
  const getUI5VersionValidationMessage = ___ui5_version_utils['getUI5VersionValidationMessage'];
34
34
  const getError = ___cpe_error_utils['getError'];
35
35
  var __exports = async function (rta) {
36
- const {version} = await VersionInfo.load();
36
+ const version = (await VersionInfo.load({ library: 'sap.ui.core' }))?.version;
37
37
  const versionParts = version.split('.');
38
38
  const minor = parseInt(versionParts[1], 10);
39
39
  const flexSettings = rta.getFlexSettings();
@@ -14,9 +14,10 @@ import VersionInfo from 'sap/ui/VersionInfo';
14
14
  import { getUI5VersionValidationMessage } from './ui5-version-utils';
15
15
  import UI5Element from 'sap/ui/dt/Element';
16
16
  import { getError } from '../cpe/error-utils';
17
+ import type {SingleVersionInfo} from '../../types/global';
17
18
 
18
19
  export default async function (rta: RuntimeAuthoring) {
19
- const { version } = (await VersionInfo.load()) as { version: string };
20
+ const version = (await VersionInfo.load({library:'sap.ui.core'}) as SingleVersionInfo)?.version;
20
21
  const versionParts = version.split('.');
21
22
  const minor = parseInt(versionParts[1], 10);
22
23
  const flexSettings = rta.getFlexSettings();
@@ -20,7 +20,7 @@ sap.ui.define([
20
20
  const storageFileChanged = ___sap_ux_private_control_property_editor_common['storageFileChanged'];
21
21
  class WorkspaceConnectorService {
22
22
  async init(sendAction) {
23
- const {version} = await VersionInfo.load();
23
+ const version = (await VersionInfo.load({ library: 'sap.ui.core' }))?.version;
24
24
  const versionParts = version.split('.');
25
25
  const minor = parseInt(versionParts[1], 10);
26
26
  if (minor > 72) {
@@ -1,6 +1,7 @@
1
1
  import { ExternalAction, storageFileChanged } from '@sap-ux-private/control-property-editor-common';
2
2
  import { ActionSenderFunction } from './types';
3
3
  import VersionInfo from 'sap/ui/VersionInfo';
4
+ import type {SingleVersionInfo} from '../../types/global';
4
5
 
5
6
  /**
6
7
  * A Class of WorkspaceConnectorService
@@ -12,7 +13,7 @@ export class WorkspaceConnectorService {
12
13
  * @param sendAction action sender function
13
14
  */
14
15
  public async init(sendAction: ActionSenderFunction): Promise<void> {
15
- const { version } = (await VersionInfo.load()) as { version: string };
16
+ const version = (await VersionInfo.load({library:'sap.ui.core'}) as SingleVersionInfo)?.version;
16
17
  const versionParts = version.split('.');
17
18
  const minor = parseInt(versionParts[1], 10);
18
19
  if (minor > 72) {
@@ -75,9 +75,9 @@ sap.ui.define(["./utils", "sap/ui/VersionInfo"], function (___utils, VersionInfo
75
75
  async function transformNodes(input, scenario, reuseComponentsIds) {
76
76
  const stack = [...input];
77
77
  const items = [];
78
- const {
79
- version
80
- } = await VersionInfo.load();
78
+ const version = (await VersionInfo.load({
79
+ library: 'sap.ui.core'
80
+ }))?.version;
81
81
  const versionParts = version.split('.');
82
82
  const minor = parseInt(versionParts[1], 10);
83
83
  while (stack.length) {
@@ -3,6 +3,7 @@ import type { OutlineViewNode } from 'sap/ui/rta/command/OutlineService';
3
3
  import type { Scenario } from 'sap/ui/fl/Scenario';
4
4
  import { isEditable, isReuseComponent } from './utils';
5
5
  import VersionInfo from 'sap/ui/VersionInfo';
6
+ import type {SingleVersionInfo} from '../../../types/global';
6
7
 
7
8
  interface AdditionalData {
8
9
  text?: string;
@@ -87,7 +88,7 @@ export async function transformNodes(
87
88
  ): Promise<OutlineNode[]> {
88
89
  const stack = [...input];
89
90
  const items: OutlineNode[] = [];
90
- const { version } = (await VersionInfo.load()) as { version: string };
91
+ const version = (await VersionInfo.load({library:'sap.ui.core'}) as SingleVersionInfo)?.version;
91
92
  const versionParts = version.split('.');
92
93
  const minor = parseInt(versionParts[1], 10);
93
94
  while (stack.length) {
@@ -68,8 +68,10 @@ sap.ui.define(["sap/base/util/merge", "sap/ui/fl/write/api/connectors/ObjectStor
68
68
  },
69
69
  loadFeatures: async function () {
70
70
  const features = await ObjectStorageConnector.loadFeatures();
71
- const ui5Version = await VersionInfo.load();
72
- const [majorVersion, minorVersion] = ui5Version.version.split('.').map(v => parseInt(v, 10));
71
+ const version = (await VersionInfo.load({
72
+ library: 'sap.ui.core'
73
+ }))?.version;
74
+ const [majorVersion, minorVersion] = version.split('.').map(v => parseInt(v, 10));
73
75
  features.isVariantAdaptationEnabled = majorVersion >= 1 && minorVersion >= 90;
74
76
  const settings = getFlexSettings();
75
77
  if (settings?.developerMode) {
@@ -2,6 +2,7 @@ import merge from 'sap/base/util/merge';
2
2
  import ObjectStorageConnector from 'sap/ui/fl/write/api/connectors/ObjectStorageConnector';
3
3
  import Layer from 'sap/ui/fl/Layer';
4
4
  import VersionInfo from 'sap/ui/VersionInfo';
5
+ import type {SingleVersionInfo} from '../../types/global';
5
6
  import { CHANGES_API_PATH, FlexChange, getFlexSettings } from './common';
6
7
 
7
8
  const connector = merge({}, ObjectStorageConnector, {
@@ -69,8 +70,8 @@ const connector = merge({}, ObjectStorageConnector, {
69
70
  loadFeatures: async function () {
70
71
  const features = await ObjectStorageConnector.loadFeatures();
71
72
 
72
- const ui5Version = (await VersionInfo.load()) as { version: string };
73
- const [majorVersion, minorVersion] = ui5Version.version.split('.').map((v: string) => parseInt(v, 10));
73
+ const version = (await VersionInfo.load({library:'sap.ui.core'}) as SingleVersionInfo)?.version;
74
+ const [majorVersion, minorVersion] = version.split('.').map((v: string) => parseInt(v, 10));
74
75
  features.isVariantAdaptationEnabled = majorVersion >= 1 && minorVersion >= 90;
75
76
  const settings = getFlexSettings();
76
77
  if (settings?.developerMode) {
@@ -0,0 +1,38 @@
1
+ /* eslint-disable @typescript-eslint/no-unsafe-assignment,
2
+ @typescript-eslint/no-unsafe-member-access,
3
+ @typescript-eslint/no-unsafe-assignment,
4
+ @typescript-eslint/no-unsafe-argument,
5
+ no-console */
6
+
7
+ /**
8
+ * Calculates the script content for accessing the right sap/ushell/bootstrap sandbox.
9
+ * @param fnCallback {Function} The callback function to be executed after the bootstrap is loaded.
10
+ */
11
+ async function ushellBootstrap(fnCallback) {
12
+ let src = '/test-resources/sap/ushell/bootstrap/sandbox.js';
13
+ try {
14
+ const response = await fetch('/resources/sap-ui-version.json');
15
+ const json = await response.json();
16
+ const version = json?.libraries?.find((lib) => lib.name === 'sap.ui.core')?.version;
17
+ const major = version ? parseInt(version.split('.')[0], 10) : 2;
18
+ if (major >= 2) {
19
+ src = '/resources/sap/ushell/bootstrap/sandbox2.js';
20
+ }
21
+ } catch (error) {
22
+ console.warn('Failed to fetch sap-ui-version.json. Assuming it is a 1.x version.');
23
+ }
24
+
25
+ // eslint-disable-next-line fiori-custom/sap-no-dom-access,fiori-custom/sap-browser-api-warning
26
+ const shellBootstrap = document.getElementById('sap-ushell-bootstrap');
27
+ if (shellBootstrap) {
28
+ shellBootstrap.onload = () => {
29
+ window['sap-ui-config']['xx-bootTask'](fnCallback);
30
+ };
31
+ shellBootstrap.setAttribute('src', src);
32
+ }
33
+ }
34
+
35
+ // eslint-disable-next-line fiori-custom/sap-no-global-define
36
+ window['sap-ui-config'] = {
37
+ 'xx-bootTask': ushellBootstrap
38
+ };
@@ -4,11 +4,19 @@ sap.ui.define([
4
4
  'open/ux/preview/client/thirdparty/@sap-ux-private/control-property-editor-common',
5
5
  'sap/ui/core/IconPool',
6
6
  'sap/base/i18n/ResourceBundle',
7
- '../adp/api-handler'
8
- ], function (Log, ___sap_ux_private_control_property_editor_common, IconPool, ResourceBundle, ___adp_api_handler) {
7
+ '../adp/api-handler',
8
+ 'sap/ui/VersionInfo',
9
+ '../cpe/error-utils',
10
+ './initConnectors'
11
+ ], function (Log, ___sap_ux_private_control_property_editor_common, IconPool, ResourceBundle, ___adp_api_handler, VersionInfo, ___cpe_error_utils, __initConnectors) {
9
12
  'use strict';
13
+ function _interopRequireDefault(obj) {
14
+ return obj && obj.__esModule && typeof obj.default !== 'undefined' ? obj.default : obj;
15
+ }
10
16
  const SCENARIO = ___sap_ux_private_control_property_editor_common['SCENARIO'];
11
17
  const getManifestAppdescr = ___adp_api_handler['getManifestAppdescr'];
18
+ const getError = ___cpe_error_utils['getError'];
19
+ const initConnectors = _interopRequireDefault(__initConnectors);
12
20
  const UI5_LIBS = [
13
21
  'sap.apf',
14
22
  'sap.base',
@@ -151,13 +159,13 @@ sap.ui.define([
151
159
  const urlParams = new URLSearchParams(window.location.search);
152
160
  const container = sap?.ushell?.Container ?? sap.ui.require('sap/ushell/Container');
153
161
  let scenario = '';
162
+ const version = (await VersionInfo.load({ library: 'sap.ui.core' }))?.version;
154
163
  if (flex) {
155
164
  const flexSettings = JSON.parse(flex);
156
165
  scenario = flexSettings.scenario;
157
166
  container.attachRendererCreatedEvent(async function () {
158
167
  const lifecycleService = await container.getServiceAsync('AppLifeCycle');
159
168
  lifecycleService.attachAppLoaded(event => {
160
- const version = sap.ui.version;
161
169
  const minor = parseInt(version.split('.')[1], 10);
162
170
  const view = event.getParameter('componentInstance');
163
171
  const flexSettings = JSON.parse(flex);
@@ -189,13 +197,15 @@ sap.ui.define([
189
197
  if (appUrls) {
190
198
  await registerComponentDependencyPaths(JSON.parse(appUrls), urlParams);
191
199
  }
200
+ await initConnectors();
192
201
  if (customInit) {
193
202
  sap.ui.require([customInit]);
194
203
  }
195
204
  const resourceBundle = await loadI18nResourceBundle(scenario);
196
205
  setI18nTitle(resourceBundle);
197
206
  registerSAPFonts();
198
- const renderer = await container.createRenderer(undefined, true);
207
+ const major = version ? parseInt(version.split('.')[0], 10) : 2;
208
+ const renderer = major < 2 ? await container.createRenderer(undefined, true) : await container.createRendererInternal(undefined, true);
199
209
  renderer.placeAt('content');
200
210
  }
201
211
  const bootstrapConfig = document.getElementById('sap-ui-bootstrap');
@@ -204,7 +214,10 @@ sap.ui.define([
204
214
  appUrls: bootstrapConfig.getAttribute('data-open-ux-preview-libs-manifests'),
205
215
  flex: bootstrapConfig.getAttribute('data-open-ux-preview-flex-settings'),
206
216
  customInit: bootstrapConfig.getAttribute('data-open-ux-preview-customInit')
207
- }).catch(() => Log.error('Sandbox initialization failed.'));
217
+ }).catch(e => {
218
+ const error = getError(e);
219
+ Log.error('Sandbox initialization failed: ' + error.message);
220
+ });
208
221
  }
209
222
  var __exports = { __esModule: true };
210
223
  __exports.resetAppState = resetAppState;
@@ -7,6 +7,10 @@ import IconPool from 'sap/ui/core/IconPool';
7
7
  import ResourceBundle from 'sap/base/i18n/ResourceBundle';
8
8
  import AppState from 'sap/ushell/services/AppState';
9
9
  import { getManifestAppdescr } from '../adp/api-handler';
10
+ import VersionInfo from 'sap/ui/VersionInfo';
11
+ import { getError } from '../cpe/error-utils';
12
+ import initConnectors from './initConnectors';
13
+ import type {SingleVersionInfo} from '../../types/global';
10
14
 
11
15
  /**
12
16
  * SAPUI5 delivered namespaces from https://ui5.sap.com/#/api/sap
@@ -264,8 +268,9 @@ export async function init({
264
268
  customInit?: string | null;
265
269
  }): Promise<void> {
266
270
  const urlParams = new URLSearchParams(window.location.search);
267
- const container = sap?.ushell?.Container ?? (sap.ui.require('sap/ushell/Container') as typeof sap.ushell.Container);
271
+ const container = sap?.ushell?.Container ?? sap.ui.require('sap/ushell/Container');
268
272
  let scenario: string = '';
273
+ const version = (await VersionInfo.load({library:'sap.ui.core'}) as SingleVersionInfo)?.version;
269
274
  // Register RTA if configured
270
275
  if (flex) {
271
276
  const flexSettings = JSON.parse(flex) as FlexSettings;
@@ -273,7 +278,6 @@ export async function init({
273
278
  container.attachRendererCreatedEvent(async function () {
274
279
  const lifecycleService = await container.getServiceAsync<AppLifeCycle>('AppLifeCycle');
275
280
  lifecycleService.attachAppLoaded((event) => {
276
- const version = sap.ui.version;
277
281
  const minor = parseInt(version.split('.')[1], 10);
278
282
  const view = event.getParameter('componentInstance');
279
283
  const flexSettings = JSON.parse(flex) as FlexSettings;
@@ -317,6 +321,9 @@ export async function init({
317
321
  await registerComponentDependencyPaths(JSON.parse(appUrls), urlParams);
318
322
  }
319
323
 
324
+ // Load rta connector
325
+ await initConnectors();
326
+
320
327
  // Load custom initialization module
321
328
  if (customInit) {
322
329
  sap.ui.require([customInit]);
@@ -326,15 +333,22 @@ export async function init({
326
333
  const resourceBundle = await loadI18nResourceBundle(scenario as Scenario);
327
334
  setI18nTitle(resourceBundle);
328
335
  registerSAPFonts();
329
- const renderer = await container.createRenderer(undefined, true);
336
+ const major = version ? parseInt(version.split('.')[0], 10) : 2;
337
+
338
+ const renderer =
339
+ major < 2
340
+ ? await container.createRenderer(undefined, true)
341
+ : await container.createRendererInternal(undefined, true);
330
342
  renderer.placeAt('content');
331
343
  }
332
-
333
344
  const bootstrapConfig = document.getElementById('sap-ui-bootstrap');
334
345
  if (bootstrapConfig) {
335
346
  init({
336
347
  appUrls: bootstrapConfig.getAttribute('data-open-ux-preview-libs-manifests'),
337
348
  flex: bootstrapConfig.getAttribute('data-open-ux-preview-flex-settings'),
338
349
  customInit: bootstrapConfig.getAttribute('data-open-ux-preview-customInit')
339
- }).catch(() => Log.error('Sandbox initialization failed.'));
350
+ }).catch((e) => {
351
+ const error = getError(e);
352
+ Log.error('Sandbox initialization failed: ' + error.message);
353
+ });
340
354
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- sap.ui.define([], function () {
3
+ sap.ui.define(["sap/ui/VersionInfo"], function (VersionInfo) {
4
4
  "use strict";
5
5
 
6
6
  /**
@@ -12,12 +12,15 @@ sap.ui.define([], function () {
12
12
  *
13
13
  * @example
14
14
  * intiConnectors(); // Simply call the function without any arguments.
15
- * @returns {void}
16
15
  */
17
- function initConnectors() {
18
- const version = sap.ui.version;
19
- const minor = parseInt(version.split('.')[1], 10);
20
- if (minor < 72) {
16
+ async function initConnectors() {
17
+ const version = (await VersionInfo.load({
18
+ library: 'sap.ui.core'
19
+ }))?.version;
20
+ const versionArray = version ? version.split('.') : ['2', '99'];
21
+ const minor = parseInt(versionArray[1], 10);
22
+ const major = parseInt(versionArray[0], 10);
23
+ if (major === 1 && minor < 72) {
21
24
  sap.ui.require(['open/ux/preview/client/flp/enableFakeConnector'], function (enableFakeConnector) {
22
25
  enableFakeConnector();
23
26
  });
@@ -25,11 +28,6 @@ sap.ui.define([], function () {
25
28
  sap.ui.define('custom.connectors.WorkspaceConnector', ['open/ux/preview/client/flp/WorkspaceConnector'], connector => connector, true);
26
29
  }
27
30
  }
28
- initConnectors();
29
- var __exports = {
30
- __esModule: true
31
- };
32
- __exports.initConnectors = initConnectors;
33
- return __exports;
31
+ return initConnectors;
34
32
  });
35
33
  //# sourceMappingURL=initConnectors.js.map
@@ -1,3 +1,6 @@
1
+ import VersionInfo from 'sap/ui/VersionInfo';
2
+ import type {SingleVersionInfo} from '../../types/global';
3
+
1
4
  /**
2
5
  * Initializes UI5 connectors based on the current UI5 version.
3
6
  *
@@ -7,13 +10,14 @@
7
10
  *
8
11
  * @example
9
12
  * intiConnectors(); // Simply call the function without any arguments.
10
- * @returns {void}
11
13
  */
12
- export function initConnectors(): void {
13
- const version = sap.ui.version;
14
- const minor = parseInt(version.split('.')[1], 10);
14
+ export default async function initConnectors(): Promise<void> {
15
+ const version = (await VersionInfo.load({library:'sap.ui.core'}) as SingleVersionInfo)?.version;
16
+ const versionArray = version ? version.split('.') : ['2', '99'];
17
+ const minor = parseInt(versionArray[1], 10);
18
+ const major = parseInt(versionArray[0], 10);
15
19
 
16
- if (minor < 72) {
20
+ if (major === 1 && minor < 72) {
17
21
  sap.ui.require(['open/ux/preview/client/flp/enableFakeConnector'], function (enableFakeConnector: () => void) {
18
22
  enableFakeConnector();
19
23
  });
@@ -26,5 +30,3 @@ export function initConnectors(): void {
26
30
  );
27
31
  }
28
32
  }
29
-
30
- initConnectors();
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "bugs": {
10
10
  "url": "https://github.com/SAP/open-ux-tools/issues?q=is%3Aopen+is%3Aissue+label%3Abug+label%3Apreview-middleware"
11
11
  },
12
- "version": "0.16.26",
12
+ "version": "0.16.28",
13
13
  "license": "Apache-2.0",
14
14
  "author": "@SAP/ux-tools-team",
15
15
  "main": "dist/index.js",
@@ -26,8 +26,8 @@
26
26
  "mem-fs": "2.1.0",
27
27
  "mem-fs-editor": "9.4.0",
28
28
  "@sap-ux/logger": "0.6.0",
29
- "@sap-ux/btp-utils": "0.15.0",
30
29
  "@sap-ux/adp-tooling": "0.12.18",
30
+ "@sap-ux/btp-utils": "0.15.0",
31
31
  "@sap-ux/control-property-editor-sources": "npm:@sap-ux/control-property-editor@0.4.26",
32
32
  "@sap-ux/project-access": "1.25.7"
33
33
  },
@@ -45,7 +45,7 @@
45
45
  "supertest": "6.3.3",
46
46
  "@sap-ux-private/playwright": "0.1.0",
47
47
  "dotenv": "16.3.1",
48
- "@private/preview-middleware-client": "npm:@sap-ux-private/preview-middleware-client@0.10.4",
48
+ "@private/preview-middleware-client": "npm:@sap-ux-private/preview-middleware-client@0.10.5",
49
49
  "@sap-ux/axios-extension": "1.16.1",
50
50
  "@sap-ux/store": "0.7.0",
51
51
  "@sap-ux/ui5-info": "0.7.0",
@@ -40,7 +40,8 @@
40
40
  };
41
41
  </script>
42
42
 
43
- <script src="<%- basePath %>/test-resources/sap/ushell/bootstrap/sandbox.js" id="sap-ushell-bootstrap"></script>
43
+ <script src="/preview/client/flp/bootstrap.js" id="preview-bootstrap"></script>
44
+ <script id="sap-ushell-bootstrap"></script>
44
45
  <!-- Bootstrap the UI5 core library. 'data-sap-ui-frameOptions="allow"'' is a NON-SECURE setting for test environments -->
45
46
  <script id="sap-ui-bootstrap"
46
47
  src="<%- basePath %>/resources/sap-ui-core.js"
@@ -61,10 +62,6 @@
61
62
  data-open-ux-preview-libs-manifests='<%- JSON.stringify(Object.values(apps).map(app => app.url)) %>'<% } %>>
62
63
  </script>
63
64
 
64
- <script type="text/javascript">
65
- (() => sap.ui.require(['open/ux/preview/client/flp/initConnectors']))()
66
- </script>
67
-
68
65
  <% if (locals.flex && flex?.developerMode) { %>
69
66
  <!-- Hides Rta native toolbar -->
70
67
  <style>