@wise/dynamic-flow-client-internal 0.1.0 → 0.2.0-beta-1a74ba.3

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/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Wise Dynamic Flow Web Client
1
+ # Dynamic Flow Web Client for Wise
2
2
 
3
3
  This is the Wise Dynamic Flow web client. It provides a simple way to integrate a Dynamic Flow into your Wise web app.
4
4
 
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ import { DynamicFlowProps } from '@wise/dynamic-flow-client';
3
+ export declare const DynamicFlow: (props: DynamicFlowProps) => JSX.Element;
4
+ export type { DynamicFlowProps, Step } from '@wise/dynamic-flow-client';
5
+ export { fixtures, translations, makeFetcher, JsonSchemaForm, isValidSchema, } from '@wise/dynamic-flow-client';
package/build/index.js ADDED
@@ -0,0 +1,17 @@
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
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ import { DynamicFlow as DynamicFlowCore } from '@wise/dynamic-flow-client';
14
+ export var DynamicFlow = function (props) {
15
+ return _jsx(DynamicFlowCore, __assign({}, props));
16
+ };
17
+ export { fixtures, translations, makeFetcher, JsonSchemaForm, isValidSchema, } from '@wise/dynamic-flow-client';
package/build/main.css ADDED
@@ -0,0 +1,185 @@
1
+ .tw-form-control textarea {
2
+ resize: vertical;
3
+ }
4
+ .camera-capture {
5
+ background: #000;
6
+ height: 100%;
7
+ left: 0;
8
+ position: fixed;
9
+ top: 0;
10
+ width: 100%;
11
+ z-index: 1030;
12
+ }
13
+ .camera-capture video {
14
+ display: block;
15
+ height: 100%;
16
+ left: 0;
17
+ object-fit: cover;
18
+ position: absolute;
19
+ top: 0;
20
+ width: 100%;
21
+ z-index: 0;
22
+ }
23
+ .camera-capture .bottom-bar {
24
+ bottom: 0;
25
+ display: flex;
26
+ flex-direction: column;
27
+ left: 0;
28
+ position: absolute;
29
+ width: 100%;
30
+ }
31
+ .camera-capture .camera-capture-btn {
32
+ align-self: center;
33
+ background-color: transparent;
34
+ background-image: none;
35
+ border: 6px solid #f8f9fa;
36
+ border-radius: 50%;
37
+ cursor: pointer;
38
+ display: inline-block;
39
+ height: 76px;
40
+ position: relative;
41
+ touch-action: manipulation;
42
+ transition: all 0.15s ease-in-out;
43
+ user-select: none;
44
+ vertical-align: middle;
45
+ width: 76px;
46
+ }
47
+ .camera-capture .camera-capture-btn:hover {
48
+ border-color: #cbd3da;
49
+ }
50
+ .camera-capture .camera-capture-btn:hover .camera-capture-btn-inner {
51
+ background-color: #cbd3da;
52
+ }
53
+ .camera-capture .camera-capture-btn:active {
54
+ border-color: #9fadba;
55
+ }
56
+ .camera-capture .camera-capture-btn:active .camera-capture-btn-inner {
57
+ background-color: #9fadba;
58
+ }
59
+ .camera-capture .camera-capture-btn:focus,
60
+ .camera-capture .camera-capture-btn:focus-visible {
61
+ outline: 0;
62
+ }
63
+ .camera-capture .camera-capture-btn .camera-capture-btn-inner {
64
+ background-color: #f8f9fa;
65
+ border-radius: 50%;
66
+ display: inline-block;
67
+ height: 60px;
68
+ margin: 2px;
69
+ transition: all 0.15s ease-in-out;
70
+ width: 60px;
71
+ }
72
+ .camera-capture svg {
73
+ display: block;
74
+ height: 100%;
75
+ left: 0;
76
+ object-fit: cover;
77
+ position: absolute;
78
+ top: 0;
79
+ width: 100%;
80
+ z-index: 0;
81
+ }
82
+ .camera-capture svg .camera-capture-text-and-image-container {
83
+ align-items: center;
84
+ display: flex;
85
+ flex-direction: column;
86
+ gap: 8px;
87
+ justify-content: center;
88
+ overflow: hidden;
89
+ position: absolute;
90
+ }
91
+ .camera-capture svg .camera-capture-instructions,
92
+ .camera-capture svg .camera-capture-title {
93
+ color: #fff;
94
+ display: block;
95
+ text-align: center;
96
+ }
97
+ .camera-capture svg .camera-capture-title {
98
+ overflow: hidden;
99
+ text-overflow: ellipsis;
100
+ white-space: normal;
101
+ }
102
+ .camera-capture svg .camera-capture-img {
103
+ display: block;
104
+ filter: invert(100%);
105
+ height: 32px;
106
+ position: relative;
107
+ width: 32px;
108
+ }
109
+ .camera-capture svg foreignObject {
110
+ overflow: visible;
111
+ }
112
+ .camera-capture .review-image {
113
+ display: block;
114
+ height: 100%;
115
+ left: 0;
116
+ object-fit: cover;
117
+ position: absolute;
118
+ top: 0;
119
+ width: 100%;
120
+ z-index: 0;
121
+ }
122
+ #camera-not-supported {
123
+ background-color: #fff;
124
+ height: 100%;
125
+ left: 0;
126
+ overflow: scroll;
127
+ position: fixed;
128
+ top: 0;
129
+ width: 100%;
130
+ z-index: 10000;
131
+ }
132
+ #no-camera-access {
133
+ background-color: #fff;
134
+ height: 100%;
135
+ left: 0;
136
+ overflow: scroll;
137
+ position: fixed;
138
+ top: 0;
139
+ width: 100%;
140
+ z-index: 10000;
141
+ }
142
+ .df-image {
143
+ display: flex;
144
+ justify-content: center;
145
+ align-items: center;
146
+ }
147
+ .df-image img {
148
+ height: auto;
149
+ width: 100%;
150
+ }
151
+ /* narrow screens */
152
+ .df-image.xs img {
153
+ width: 50px;
154
+ }
155
+ .df-image.sm img {
156
+ width: 100px;
157
+ }
158
+ .df-image.md img {
159
+ width: 200px;
160
+ }
161
+ .df-image.lg img {
162
+ width: 300px;
163
+ }
164
+ /* wide screens */
165
+ @media (min-width: 576px) {
166
+ .df-image.xs img {
167
+ width: 100px;
168
+ }
169
+
170
+ .df-image.sm img {
171
+ width: 200px;
172
+ }
173
+
174
+ .df-image.md img {
175
+ width: 300px;
176
+ }
177
+
178
+ .df-image.lg img {
179
+ width: 500px;
180
+ }
181
+
182
+ .df-image.xl img {
183
+ max-width: 600px;
184
+ }
185
+ }
@@ -0,0 +1 @@
1
+ export declare const getObjectKeys: <T>(object: T) => (keyof T)[];
@@ -0,0 +1,30 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { action } from '@storybook/addon-actions';
3
+ import { storiesOf } from '@storybook/react';
4
+ import { fixtures } from '@wise/dynamic-flow-client';
5
+ import { DynamicFlow } from '../index';
6
+ import EditableDynamicFlow from './EditableDynamicFlow';
7
+ import { fixtureFetcher } from './fixtureFetcher';
8
+ export var getObjectKeys = Object.keys;
9
+ var storyMap = {};
10
+ var allStepNames = getObjectKeys(fixtures.steps);
11
+ allStepNames.forEach(function (stepName) {
12
+ var _a;
13
+ var label = (_a = fixtures.steps[stepName].key) !== null && _a !== void 0 ? _a : stepName;
14
+ var _b = label.split('/'), group = _b[0], name = _b[1];
15
+ if (!storyMap[group]) {
16
+ storyMap[group] = storiesOf("Dynamic Flow/".concat(group), module);
17
+ }
18
+ storyMap[group].add(name, function () { return (_jsx(DynamicFlow, { flowId: "storybook", initialAction: { method: 'GET', url: "/steps/".concat(stepName) }, fetcher: fixtureFetcher, loaderConfig: { size: 'xl', initial: true, submission: false }, onComplete: action('onComplete'), onStepChange: action('onStepChange'), onError: action('onError'), onEvent: action('onEvent'), onLog: action('onLog') }, stepName)); });
19
+ });
20
+ var editable = storiesOf("Dynamic Flow/Editable", module);
21
+ editable.add('Dynamic Flow', EditableDynamicFlow, {
22
+ argTypes: {
23
+ initialStepName: {
24
+ label: 'Initial Step',
25
+ control: 'select',
26
+ options: Object.keys(fixtures.steps)
27
+ }
28
+ },
29
+ args: { initialStepName: Object.keys(fixtures)[0] }
30
+ });
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ declare const EditableDynamicFlow: ({ initialStepName }: {
3
+ initialStepName?: string | undefined;
4
+ }) => JSX.Element;
5
+ export default EditableDynamicFlow;
@@ -0,0 +1,62 @@
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
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
+ /* eslint-disable react/forbid-dom-props */
14
+ import { action } from '@storybook/addon-actions';
15
+ import { fixtures } from '@wise/dynamic-flow-client';
16
+ import { useState } from 'react';
17
+ import { DynamicFlow } from '../index';
18
+ import { fixtureFetcher } from './fixtureFetcher';
19
+ var EditableDynamicFlow = function (_a) {
20
+ var _b = _a.initialStepName, initialStepName = _b === void 0 ? '' : _b;
21
+ var selectedStep = fixtures.steps[initialStepName] || {};
22
+ var selectedInitialStep = JSON.stringify(selectedStep, null, 2);
23
+ return _jsx(InteractiveDemo, { selectedInitialStep: selectedInitialStep }, selectedInitialStep);
24
+ };
25
+ var InteractiveDemo = function (_a) {
26
+ var selectedInitialStep = _a.selectedInitialStep;
27
+ var _b = useState(selectedInitialStep), initialStep = _b[0], setInitialStep = _b[1];
28
+ var onTextAreaChange = function (event) {
29
+ setInitialStep(event.target.value);
30
+ };
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, { flowId: "storybook", initialStep: safeParseStepJson(initialStep), fetcher: fixtureFetcher, onComplete: action('onComplete'), onStepChange: action('onStepChange'), onError: action('onError'), onEvent: action('onEvent'), onLog: action('onLog') }, initialStep) }))] })));
32
+ };
33
+ function safeParseStepJson(jsonStep) {
34
+ try {
35
+ return JSON.parse(jsonStep);
36
+ }
37
+ catch (_a) {
38
+ // eslint-disable-next-line no-console
39
+ console.warn('JSON parsing error');
40
+ return {
41
+ type: 'final',
42
+ layout: [
43
+ {
44
+ type: 'box',
45
+ width: 'lg',
46
+ components: [
47
+ {
48
+ type: 'alert',
49
+ markdown: "**Error parsing JSON.**",
50
+ context: 'warning'
51
+ },
52
+ {
53
+ type: 'paragraph',
54
+ text: " Invalid syntax or missing elements are preventing the JSON code you entered from being parsed. Carefully review and edit the code for errors such as missing commas or brackets."
55
+ },
56
+ ]
57
+ },
58
+ ]
59
+ };
60
+ }
61
+ }
62
+ export default EditableDynamicFlow;
@@ -0,0 +1,3 @@
1
+ type Fetcher = typeof window.fetch;
2
+ export declare const fixtureFetcher: Fetcher;
3
+ export {};
@@ -0,0 +1,116 @@
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 { fixtures } from '@wise/dynamic-flow-client';
50
+ import { getObjectKeys } from './DynamicFlow.story';
51
+ var isObject = function (val) {
52
+ return typeof val === 'object' && val !== null;
53
+ };
54
+ export var fixtureFetcher = function (input, init) { return __awaiter(void 0, void 0, void 0, function () {
55
+ var url;
56
+ return __generator(this, function (_a) {
57
+ action('fixtureFetcher')(input, init);
58
+ url = getURL(input);
59
+ if (url.pathname.startsWith('/steps/')) {
60
+ return [2 /*return*/, respondWithFixture(fixtures.steps, url, init)];
61
+ }
62
+ if (url.pathname.startsWith('/responses/')) {
63
+ return [2 /*return*/, respondWithFixture(fixtures.responses, url, init)];
64
+ }
65
+ if (url.pathname.startsWith('/validate')) {
66
+ return [2 /*return*/, new Response(JSON.stringify({ message: 'Validation-async OK' }))];
67
+ }
68
+ return [2 /*return*/, new Response(null, { status: 404 })];
69
+ });
70
+ }); };
71
+ var getURL = function (input) {
72
+ if (input instanceof URL) {
73
+ return input;
74
+ }
75
+ if (input instanceof Request) {
76
+ return new URL(input.url, 'http://foo');
77
+ }
78
+ return new URL(input, 'http://foo');
79
+ };
80
+ var respondWithFixture = function (fixtures, url, init) { return __awaiter(void 0, void 0, void 0, function () {
81
+ var fixtureNames, name, fixture, body;
82
+ var _a;
83
+ return __generator(this, function (_b) {
84
+ switch (_b.label) {
85
+ case 0:
86
+ fixtureNames = getObjectKeys(fixtures);
87
+ name = url.pathname
88
+ .split('/')
89
+ .filter(function (part) { return !!part; })
90
+ .pop();
91
+ if (!fixtureNames.includes(name !== null && name !== void 0 ? name : '')) return [3 /*break*/, 3];
92
+ fixture = fixtures[name];
93
+ if (!url.searchParams.has('delay')) return [3 /*break*/, 2];
94
+ return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, Number(url.searchParams.get('delay'))); })];
95
+ case 1:
96
+ _b.sent();
97
+ _b.label = 2;
98
+ case 2:
99
+ // by convention if the url contains a "refresh"query parameterm we use the payload as model
100
+ if (url.searchParams.has('refresh') &&
101
+ (init === null || init === void 0 ? void 0 : init.body) &&
102
+ typeof init.body === 'string' &&
103
+ isObject(fixture)) {
104
+ body = JSON.parse(init.body);
105
+ return [2 /*return*/, new Response(JSON.stringify(__assign(__assign({}, fixture), { model: __assign(__assign({}, ((_a = fixture.model) !== null && _a !== void 0 ? _a : {})), body) })))];
106
+ }
107
+ if (url.pathname.includes('exit')) {
108
+ return [2 /*return*/, new Response(JSON.stringify(fixture), { headers: { 'X-DF-Exit': 'true' } })];
109
+ }
110
+ return [2 /*return*/, new Response(JSON.stringify(fixture))];
111
+ case 3:
112
+ action('ERROR 404')(url);
113
+ return [2 /*return*/, new Response(null, { status: 404 })];
114
+ }
115
+ });
116
+ }); };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wise/dynamic-flow-client-internal",
3
- "version": "0.1.0",
3
+ "version": "0.2.0-beta-1a74ba.3",
4
4
  "description": "Dynamic Flow web client for Wise",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",