@wise/dynamic-flow-client 0.2.0 → 0.2.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/build/flow/DynamicFlow.d.ts +1 -0
- package/build/flow/DynamicFlow.js +15 -5
- package/build/flow/DynamicFlowStep.d.ts +1 -0
- package/build/flow/errorBoundary/ErrorBoundaryAlert.d.ts +1 -0
- package/build/flow/fixtures/components/alert.d.ts +2 -2
- package/build/flow/fixtures/components/box.d.ts +2 -2
- package/build/flow/fixtures/components/button.d.ts +2 -2
- package/build/flow/fixtures/components/columns.d.ts +2 -2
- package/build/flow/fixtures/components/copyable.d.ts +2 -2
- package/build/flow/fixtures/components/decision.d.ts +2 -2
- package/build/flow/fixtures/components/heading.d.ts +2 -2
- package/build/flow/fixtures/components/image.d.ts +3 -2
- package/build/flow/fixtures/components/image.js +22 -3
- package/build/flow/fixtures/components/info.d.ts +2 -2
- package/build/flow/fixtures/components/list.d.ts +2 -2
- package/build/flow/fixtures/components/loading-indicator.d.ts +2 -2
- package/build/flow/fixtures/components/paragraph.d.ts +2 -2
- package/build/flow/fixtures/components/review.d.ts +2 -2
- package/build/flow/fixtures/examples/camera-capture.d.ts +2 -2
- package/build/flow/fixtures/examples/recipient-update.d.ts +2 -2
- package/build/flow/fixtures/examples/recipient-update.js +2 -2
- package/build/flow/fixtures/examples/recipient.d.ts +2 -2
- package/build/flow/fixtures/examples/single-file-upload.d.ts +2 -2
- package/build/flow/fixtures/examples/single-file-upload.js +32 -30
- package/build/flow/fixtures/examples/step-validation-errors.d.ts +2 -2
- package/build/flow/fixtures/features/action-response.d.ts +2 -2
- package/build/flow/fixtures/features/external.d.ts +2 -2
- package/build/flow/fixtures/features/persist-async.d.ts +2 -2
- package/build/flow/fixtures/features/polling.d.ts +2 -2
- package/build/flow/fixtures/features/validation-async.d.ts +3 -0
- package/build/flow/fixtures/features/validation-async.js +38 -0
- package/build/flow/fixtures/index.d.ts +34 -28
- package/build/flow/fixtures/index.js +8 -1
- package/build/flow/fixtures/responses/action-response-final.d.ts +2 -2
- package/build/flow/fixtures/responses/recipient-update-final.d.ts +2 -2
- package/build/flow/fixtures/schemas/basic-form.d.ts +2 -2
- package/build/flow/fixtures/schemas/number-and-integer.d.ts +2 -2
- package/build/flow/fixtures/schemas/one-of.d.ts +2 -2
- package/build/flow/fixtures/schemas/string-formats.d.ts +2 -2
- package/build/flow/fixtures/schemas/string-formats.js +6 -2
- package/build/flow/stories/DynamicFlow.story.d.ts +1 -0
- package/build/flow/stories/DynamicFlow.story.js +30 -0
- package/build/flow/stories/EditableDynamicFlow.d.ts +1 -0
- package/build/flow/stories/EditableDynamicFlow.js +2 -1
- package/build/flow/stories/fixtureFetcher.d.ts +2 -0
- package/build/flow/stories/fixtureFetcher.js +114 -0
- package/build/jsonSchemaForm/JsonSchemaForm.d.ts +1 -0
- package/build/jsonSchemaForm/allOfSchema/AllOfSchema.d.ts +1 -0
- package/build/jsonSchemaForm/arrayTypeSchema/ArraySchema.d.ts +1 -0
- package/build/jsonSchemaForm/arrayTypeSchema/arrayListSchema/ArrayListSchema.d.ts +1 -0
- package/build/jsonSchemaForm/arrayTypeSchema/arrayListSchema/multipleFileUploadSchema/MultipleFileUploadSchema.d.ts +1 -0
- package/build/jsonSchemaForm/basicTypeSchema/BasicTypeSchema.d.ts +1 -0
- package/build/jsonSchemaForm/controlFeedback/ControlFeedback.d.ts +1 -0
- package/build/jsonSchemaForm/genericSchema/GenericSchema.d.ts +1 -0
- package/build/jsonSchemaForm/help/Help.d.ts +1 -0
- package/build/jsonSchemaForm/objectSchema/ObjectSchema.d.ts +1 -0
- package/build/jsonSchemaForm/oneOfSchema/OneOfSchema.d.ts +1 -0
- package/build/jsonSchemaForm/persistAsyncSchema/PersistAsyncSchema.d.ts +1 -0
- package/build/jsonSchemaForm/persistAsyncSchema/basic/PersistAsyncBasicSchema.d.ts +1 -0
- package/build/jsonSchemaForm/persistAsyncSchema/blob/PersistAsyncBlobSchema.d.ts +1 -0
- package/build/jsonSchemaForm/persistAsyncSchema/blob/UploadInputAdapter.d.ts +1 -0
- package/build/jsonSchemaForm/promotedOneOfSchema/PromotedOneOfSchema.d.ts +1 -0
- package/build/jsonSchemaForm/promotedOneOfSchema/control/PromotedOneOfCheckboxControl.d.ts +1 -0
- package/build/jsonSchemaForm/promotedOneOfSchema/control/PromotedOneOfRadioControl.d.ts +1 -0
- package/build/jsonSchemaForm/readOnlySchema/ReadOnlySchema.d.ts +1 -0
- package/build/jsonSchemaForm/schemaFormControl/SchemaFormControl.d.ts +2 -1
- package/build/jsonSchemaForm/schemaFormControl/optionMapper.d.ts +7 -11
- package/build/jsonSchemaForm/schemaFormControl/optionMapper.js +12 -6
- package/build/jsonSchemaForm/validationAsyncSchema/ValidationAsyncSchema.d.ts +1 -0
- package/build/layout/DynamicLayout.d.ts +1 -0
- package/build/layout/alert/index.d.ts +1 -0
- package/build/layout/box/index.d.ts +1 -0
- package/build/layout/button/index.d.ts +1 -0
- package/build/layout/columns/index.d.ts +1 -0
- package/build/layout/decision/index.d.ts +1 -0
- package/build/layout/divider/index.d.ts +1 -0
- package/build/layout/external/DynamicExternal.d.ts +1 -0
- package/build/layout/form/index.d.ts +1 -0
- package/build/layout/heading/index.d.ts +1 -0
- package/build/layout/icon/index.d.ts +1 -0
- package/build/layout/image/index.d.ts +4 -2
- package/build/layout/image/index.js +17 -38
- package/build/layout/info/index.d.ts +1 -0
- package/build/layout/list/index.d.ts +1 -0
- package/build/layout/loading-indicator/index.d.ts +1 -0
- package/build/layout/paragraph/DynamicParagraph.d.ts +1 -0
- package/build/layout/review/index.d.ts +1 -0
- package/build/main.css +45 -0
- package/build/step/cameraStep/CameraStep.d.ts +1 -0
- package/build/step/cameraStep/cameraCapture/CameraCapture.d.ts +1 -0
- package/build/step/cameraStep/cameraCapture/components/index.d.ts +1 -0
- package/build/step/cameraStep/cameraCapture/overlay/Overlay.d.ts +1 -0
- package/build/step/cameraStep/cameraCapture/screens/CameraNotSupported/CameraNotSupported.d.ts +1 -0
- package/build/step/cameraStep/cameraCapture/screens/NoCameraAccess/NoCameraAccess.d.ts +1 -0
- package/build/step/externalConfirmationStep/ExternalConfirmationStep.d.ts +1 -0
- package/build/step/layoutStep/LayoutStep.d.ts +1 -0
- package/package.json +7 -5
- package/build/common/hooks/useDebouncedFunction.test.d.ts +0 -1
- package/build/common/hooks/useDebouncedFunction.test.js +0 -59
- package/build/common/logging/spec.d.ts +0 -1
- package/build/common/logging/spec.js +0 -45
- package/build/common/tracking/spec.d.ts +0 -1
- package/build/common/tracking/spec.js +0 -49
- package/build/common/utils/generate-random-id.test.d.ts +0 -1
- package/build/common/utils/generate-random-id.test.js +0 -12
- package/build/common/validation/rule-validators/spec.d.ts +0 -1
- package/build/common/validation/rule-validators/spec.js +0 -145
- package/build/common/validation/schema-validators/spec.d.ts +0 -1
- package/build/common/validation/schema-validators/spec.js +0 -137
- package/build/common/validation/valid-model/spec.d.ts +0 -1
- package/build/common/validation/valid-model/spec.js +0 -605
- package/build/common/validation/validation-failures/spec.d.ts +0 -1
- package/build/common/validation/validation-failures/spec.js +0 -185
- package/build/flow/response-parsers/spec.d.ts +0 -1
- package/build/flow/response-parsers/spec.js +0 -263
- package/build/layout/loading-indicator/spec.d.ts +0 -1
- package/build/layout/loading-indicator/spec.js +0 -11
|
@@ -15,6 +15,7 @@ import { action } from '@storybook/addon-actions';
|
|
|
15
15
|
import { useState } from 'react';
|
|
16
16
|
import DynamicFlow from '../DynamicFlow';
|
|
17
17
|
import { fixtures } from '../fixtures';
|
|
18
|
+
import { fixtureFetcher } from './fixtureFetcher';
|
|
18
19
|
var EditableDynamicFlow = function (_a) {
|
|
19
20
|
var _b = _a.initialStepName, initialStepName = _b === void 0 ? '' : _b;
|
|
20
21
|
var selectedStep = fixtures.steps[initialStepName] || {};
|
|
@@ -27,7 +28,7 @@ var InteractiveDemo = function (_a) {
|
|
|
27
28
|
var onTextAreaChange = function (event) {
|
|
28
29
|
setInitialStep(event.target.value);
|
|
29
30
|
};
|
|
30
|
-
return (_jsxs("div", __assign({ style: { display: 'flex', gap: '1em' } }, { children: [_jsxs("div", __assign({ style: { flexBasis: '50%' } }, { children: [_jsx("h3", { children: "Editable Demo" }), _jsxs("p", { children: ["You can select an initial step from the drop down in the controls panel.", _jsx("br", {}), "You can edit the JSON below and see the result on the right."] }), _jsx("textarea", { wrap: "off", rows: 40, style: { fontFamily: 'monospace', fontSize: '0.9em', width: '100%' }, value: initialStep, onChange: onTextAreaChange })] })), _jsx("div", __assign({ style: { flexBasis: '50%' } }, { children: _jsx(DynamicFlow, { initialStep: safeParseStepJson(initialStep), fetcher:
|
|
31
|
+
return (_jsxs("div", __assign({ style: { display: 'flex', gap: '1em' } }, { children: [_jsxs("div", __assign({ style: { flexBasis: '50%' } }, { children: [_jsx("h3", { children: "Editable Demo" }), _jsxs("p", { children: ["You can select an initial step from the drop down in the controls panel.", _jsx("br", {}), "You can edit the JSON below and see the result on the right."] }), _jsx("textarea", { wrap: "off", rows: 40, style: { fontFamily: 'monospace', fontSize: '0.9em', width: '100%' }, value: initialStep, onChange: onTextAreaChange })] })), _jsx("div", __assign({ style: { flexBasis: '50%' } }, { children: _jsx(DynamicFlow, { initialStep: safeParseStepJson(initialStep), fetcher: fixtureFetcher, onClose: action('onClose'), onStepChange: action('onStepChange'), onError: action('onError'), onTrackableEvent: action('onTrackableEvent'), onLog: action('onLog') }, initialStep) }))] })));
|
|
31
32
|
};
|
|
32
33
|
function safeParseStepJson(jsonStep) {
|
|
33
34
|
try {
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
23
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
+
function step(op) {
|
|
26
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
28
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
29
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
+
switch (op[0]) {
|
|
31
|
+
case 0: case 1: t = op; break;
|
|
32
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
+
default:
|
|
36
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
+
if (t[2]) _.ops.pop();
|
|
41
|
+
_.trys.pop(); continue;
|
|
42
|
+
}
|
|
43
|
+
op = body.call(thisArg, _);
|
|
44
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
import { action } from '@storybook/addon-actions';
|
|
49
|
+
import { isObject } from '@transferwise/neptune-validation';
|
|
50
|
+
import { fixtures } from '../fixtures';
|
|
51
|
+
import { getObjectKeys } from './DynamicFlow.story';
|
|
52
|
+
export var fixtureFetcher = function (input, init) { return __awaiter(void 0, void 0, void 0, function () {
|
|
53
|
+
var url;
|
|
54
|
+
return __generator(this, function (_a) {
|
|
55
|
+
action('fixtureFetcher')(input, init);
|
|
56
|
+
url = getURL(input);
|
|
57
|
+
if (url.pathname.startsWith('/steps/')) {
|
|
58
|
+
return [2 /*return*/, respondWithFixture(fixtures.steps, url, init)];
|
|
59
|
+
}
|
|
60
|
+
if (url.pathname.startsWith('/responses/')) {
|
|
61
|
+
return [2 /*return*/, respondWithFixture(fixtures.responses, url, init)];
|
|
62
|
+
}
|
|
63
|
+
if (url.pathname.startsWith('/validate')) {
|
|
64
|
+
return [2 /*return*/, new Response(JSON.stringify({ message: 'Validation-async OK' }))];
|
|
65
|
+
}
|
|
66
|
+
return [2 /*return*/, new Response(null, { status: 404 })];
|
|
67
|
+
});
|
|
68
|
+
}); };
|
|
69
|
+
var getURL = function (input) {
|
|
70
|
+
if (input instanceof URL) {
|
|
71
|
+
return input;
|
|
72
|
+
}
|
|
73
|
+
if (input instanceof Request) {
|
|
74
|
+
return new URL(input.url, 'http://foo');
|
|
75
|
+
}
|
|
76
|
+
return new URL(input, 'http://foo');
|
|
77
|
+
};
|
|
78
|
+
var respondWithFixture = function (fixtures, url, init) { return __awaiter(void 0, void 0, void 0, function () {
|
|
79
|
+
var fixtureNames, name, fixture, body;
|
|
80
|
+
var _a;
|
|
81
|
+
return __generator(this, function (_b) {
|
|
82
|
+
switch (_b.label) {
|
|
83
|
+
case 0:
|
|
84
|
+
fixtureNames = getObjectKeys(fixtures);
|
|
85
|
+
name = url.pathname
|
|
86
|
+
.split('/')
|
|
87
|
+
.filter(function (part) { return !!part; })
|
|
88
|
+
.pop();
|
|
89
|
+
if (!fixtureNames.includes(name !== null && name !== void 0 ? name : '')) return [3 /*break*/, 3];
|
|
90
|
+
fixture = fixtures[name];
|
|
91
|
+
if (!url.searchParams.has('delay')) return [3 /*break*/, 2];
|
|
92
|
+
return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, Number(url.searchParams.get('delay'))); })];
|
|
93
|
+
case 1:
|
|
94
|
+
_b.sent();
|
|
95
|
+
_b.label = 2;
|
|
96
|
+
case 2:
|
|
97
|
+
// by convention if the url contains a "refresh"query parameterm we use the payload as model
|
|
98
|
+
if (url.searchParams.has('refresh') &&
|
|
99
|
+
(init === null || init === void 0 ? void 0 : init.body) &&
|
|
100
|
+
typeof init.body === 'string' &&
|
|
101
|
+
isObject(fixture)) {
|
|
102
|
+
body = JSON.parse(init.body);
|
|
103
|
+
return [2 /*return*/, new Response(JSON.stringify(__assign(__assign({}, fixture), { model: __assign(__assign({}, ((_a = fixture.model) !== null && _a !== void 0 ? _a : {})), body) })))];
|
|
104
|
+
}
|
|
105
|
+
if (url.pathname.includes('exit')) {
|
|
106
|
+
return [2 /*return*/, new Response(JSON.stringify(fixture), { headers: { 'X-DF-Exit': 'true' } })];
|
|
107
|
+
}
|
|
108
|
+
return [2 /*return*/, new Response(JSON.stringify(fixture))];
|
|
109
|
+
case 3:
|
|
110
|
+
action('ERROR 404')(url);
|
|
111
|
+
return [2 /*return*/, new Response(null, { status: 404 })];
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}); };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import { ArrayModel } from '../../../../dynamic-flow-types';
|
|
2
3
|
import { MultipleFileUploadSchema as MultipleFileUploadSchemaType } from '../../../../dynamic-flow-types/Schema';
|
|
3
4
|
import { GenericSchemaProps } from '../../../genericSchema/GenericSchema';
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import { PersistAsync, Schema } from '../../../dynamic-flow-types';
|
|
2
3
|
import { GenericSchemaProps } from '../../genericSchema/GenericSchema';
|
|
3
4
|
export declare const getIdFromResponse: (idProperty: string, response: Record<string, unknown>) => string | number;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import { FormControlType } from '../../common';
|
|
2
3
|
import { BasicModel, Schema } from '../../dynamic-flow-types';
|
|
3
4
|
export declare const getControlType: (schema: Schema) => (typeof FormControlType)[keyof typeof FormControlType] | undefined;
|
|
@@ -11,7 +12,7 @@ declare const SchemaFormControl: {
|
|
|
11
12
|
disabled: boolean;
|
|
12
13
|
};
|
|
13
14
|
};
|
|
14
|
-
type SchemaFormControlProps = {
|
|
15
|
+
export type SchemaFormControlProps = {
|
|
15
16
|
id: string;
|
|
16
17
|
value: BasicModel | null;
|
|
17
18
|
schema: Schema;
|
|
@@ -1,24 +1,20 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import { Icon, Image, Schema } from '../../dynamic-flow-types';
|
|
2
|
-
export declare const mapConstSchemaToOption: (schema: Schema, controlType?: string) =>
|
|
3
|
-
|
|
3
|
+
export declare const mapConstSchemaToOption: (schema: Schema, controlType?: string) => RadioOption | SelectOption;
|
|
4
|
+
export type RadioOption = {
|
|
4
5
|
disabled?: boolean | undefined;
|
|
5
|
-
|
|
6
|
+
avatar?: JSX.Element | undefined;
|
|
6
7
|
currency?: string | undefined;
|
|
7
8
|
label: string;
|
|
8
9
|
value: string;
|
|
9
|
-
}
|
|
10
|
-
|
|
10
|
+
};
|
|
11
|
+
export type SelectOption = {
|
|
12
|
+
searchStrings?: string[];
|
|
11
13
|
disabled?: boolean | undefined;
|
|
12
14
|
icon?: JSX.Element | undefined;
|
|
13
15
|
currency?: string | undefined;
|
|
14
16
|
label: string;
|
|
15
17
|
value: string;
|
|
16
|
-
} | {
|
|
17
|
-
disabled?: boolean | undefined;
|
|
18
|
-
avatar?: JSX.Element | undefined;
|
|
19
|
-
currency?: string | undefined;
|
|
20
|
-
label: string;
|
|
21
|
-
value: string;
|
|
22
18
|
};
|
|
23
19
|
export declare const mapImage: (image?: Image) => {
|
|
24
20
|
icon: JSX.Element;
|
|
@@ -17,16 +17,22 @@ import { getCurrencyFlag } from './availableCurrencyFlags';
|
|
|
17
17
|
export var mapConstSchemaToOption = function (schema, controlType) {
|
|
18
18
|
switch (controlType) {
|
|
19
19
|
case 'select':
|
|
20
|
-
return
|
|
21
|
-
// TODO: LOW avoid type assertion -- using || '' would fail some tests
|
|
22
|
-
label: schema.title, value: schema["const"] }, getOptionDescription(schema.title, schema.description)), mapIcon(schema.icon)), mapCurrency(schema.icon)), mapImage(schema.image)), getDisabled(schema.disabled)), mapKeywordsToSearchStrings(schema.keywords));
|
|
20
|
+
return mapConstSchemaToSelectOption(schema);
|
|
23
21
|
case 'radio':
|
|
24
22
|
default:
|
|
25
|
-
return
|
|
26
|
-
// TODO: LOW avoid type assertion -- using || '' would fail some tests
|
|
27
|
-
label: schema.title, value: schema["const"] }, getOptionDescription(schema.title, schema.description)), mapIconToAvatar(schema.icon)), mapCurrency(schema.icon)), mapAvatar(schema.image)), getDisabled(schema.disabled));
|
|
23
|
+
return mapConstSchemaToRadioOption(schema);
|
|
28
24
|
}
|
|
29
25
|
};
|
|
26
|
+
var mapConstSchemaToRadioOption = function (schema) {
|
|
27
|
+
return __assign(__assign(__assign(__assign(__assign({
|
|
28
|
+
// TODO: LOW avoid type assertion -- using || '' would fail some tests
|
|
29
|
+
label: schema.title, value: schema["const"] }, getOptionDescription(schema.title, schema.description)), mapIconToAvatar(schema.icon)), mapCurrency(schema.icon)), mapAvatar(schema.image)), getDisabled(schema.disabled));
|
|
30
|
+
};
|
|
31
|
+
var mapConstSchemaToSelectOption = function (schema) {
|
|
32
|
+
return __assign(__assign(__assign(__assign(__assign(__assign({
|
|
33
|
+
// TODO: LOW avoid type assertion -- using || '' would fail some tests
|
|
34
|
+
label: schema.title, value: schema["const"] }, getOptionDescription(schema.title, schema.description)), mapIcon(schema.icon)), mapCurrency(schema.icon)), mapImage(schema.image)), getDisabled(schema.disabled)), mapKeywordsToSearchStrings(schema.keywords));
|
|
35
|
+
};
|
|
30
36
|
// TODO: LOW avoid type assertion below -- icon.name may be undefined
|
|
31
37
|
var mapCurrency = function (icon) { return (icon ? getCurrencyFlag(icon.name) : null); };
|
|
32
38
|
var mapKeywordsToSearchStrings = function (searchStrings) {
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import { ImageLayout } from '../../dynamic-flow-types';
|
|
2
|
-
|
|
3
|
+
type DynamicImageProps = {
|
|
3
4
|
component: ImageLayout;
|
|
4
|
-
}
|
|
5
|
+
};
|
|
6
|
+
declare const DynamicImage: ({ component: image }: DynamicImageProps) => JSX.Element | null;
|
|
5
7
|
export default DynamicImage;
|
|
@@ -51,24 +51,24 @@ import { useEffect, useState } from 'react';
|
|
|
51
51
|
import { isRelativePath } from '../../common/api/utils';
|
|
52
52
|
import { useFetcher } from '../../common/contexts/fetcherContext';
|
|
53
53
|
import { getMarginBottom } from '../utils';
|
|
54
|
-
var
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
54
|
+
var DynamicImage = function (_a) {
|
|
55
|
+
var image = _a.component;
|
|
56
|
+
var url = image.url, size = image.size, text = image.text, margin = image.margin;
|
|
57
|
+
var fetcher = useFetcher();
|
|
58
|
+
var _b = useState(''), imageSource = _b[0], setImageSource = _b[1];
|
|
59
|
+
useEffect(function () {
|
|
60
|
+
void getImageSource(fetcher, url).then(setImageSource);
|
|
61
|
+
}, [url, fetcher]);
|
|
62
|
+
var imageProps = {
|
|
63
|
+
alt: text || '',
|
|
64
|
+
src: imageSource,
|
|
65
|
+
stretch: true,
|
|
66
|
+
shrink: true
|
|
67
|
+
};
|
|
68
|
+
if (!imageSource) {
|
|
69
|
+
return null;
|
|
67
70
|
}
|
|
68
|
-
};
|
|
69
|
-
var getImageClasses = function (image) {
|
|
70
|
-
var margin = getMarginBottom(image.margin || 'lg');
|
|
71
|
-
return "img-responsive ".concat(margin);
|
|
71
|
+
return (_jsx("div", __assign({ className: "df-image ".concat(size || 'xl') }, { children: _jsx(Image, __assign({ className: "img-responsive ".concat(getMarginBottom(margin || 'lg')) }, imageProps)) })));
|
|
72
72
|
};
|
|
73
73
|
var readImageBlobAsDataURL = function (imageBlob) {
|
|
74
74
|
// we can safely assume the type of reader.result is string
|
|
@@ -102,25 +102,4 @@ var getImageSource = function (fetcher, imageUrl) { return __awaiter(void 0, voi
|
|
|
102
102
|
return [2 /*return*/];
|
|
103
103
|
});
|
|
104
104
|
}); };
|
|
105
|
-
var DynamicImage = function (props) {
|
|
106
|
-
var image = props.component;
|
|
107
|
-
var fetcher = useFetcher();
|
|
108
|
-
var _a = useState(''), imageSource = _a[0], setImageSource = _a[1];
|
|
109
|
-
useEffect(function () {
|
|
110
|
-
void getImageSource(fetcher, image.url).then(setImageSource);
|
|
111
|
-
}, [image.url, fetcher]);
|
|
112
|
-
var imageProps = {
|
|
113
|
-
alt: image.text || '',
|
|
114
|
-
src: imageSource,
|
|
115
|
-
stretch: true,
|
|
116
|
-
shrink: true
|
|
117
|
-
};
|
|
118
|
-
var getImage = function () {
|
|
119
|
-
return imageSource ? _jsx(Image, __assign({ className: getImageClasses(image) }, imageProps)) : null;
|
|
120
|
-
};
|
|
121
|
-
if (!image.size || image.size === 'xl') {
|
|
122
|
-
return getImage();
|
|
123
|
-
}
|
|
124
|
-
return (_jsx("div", __assign({ className: "row m-b-0" }, { children: _jsx("div", __assign({ className: getWrapperClasses(image) }, { children: getImage() })) })));
|
|
125
|
-
};
|
|
126
105
|
export default DynamicImage;
|
package/build/main.css
CHANGED
|
@@ -141,3 +141,48 @@
|
|
|
141
141
|
width: 100%;
|
|
142
142
|
z-index: 10000;
|
|
143
143
|
}
|
|
144
|
+
.df-image {
|
|
145
|
+
display: flex;
|
|
146
|
+
justify-content: center;
|
|
147
|
+
align-items: center;
|
|
148
|
+
}
|
|
149
|
+
.df-image img {
|
|
150
|
+
height: auto;
|
|
151
|
+
width: 100%;
|
|
152
|
+
}
|
|
153
|
+
/* narrow screens */
|
|
154
|
+
.df-image.xs img {
|
|
155
|
+
width: 50px;
|
|
156
|
+
}
|
|
157
|
+
.df-image.sm img {
|
|
158
|
+
width: 100px;
|
|
159
|
+
}
|
|
160
|
+
.df-image.md img {
|
|
161
|
+
width: 200px;
|
|
162
|
+
}
|
|
163
|
+
.df-image.lg img {
|
|
164
|
+
width: 300px;
|
|
165
|
+
}
|
|
166
|
+
/* wide screens */
|
|
167
|
+
@media (min-width: 576px) {
|
|
168
|
+
.df-image.xs img {
|
|
169
|
+
width: 100px;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
.df-image.sm img {
|
|
173
|
+
width: 200px;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
.df-image.md img {
|
|
177
|
+
width: 300px;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
.df-image.lg img {
|
|
181
|
+
width: 500px;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
.df-image.xl img {
|
|
185
|
+
max-width: 600px;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
}
|