@player-ui/reference-assets-plugin-react 0.0.1-next.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/dist/index.cjs.js +478 -0
- package/dist/index.d.ts +85 -0
- package/dist/index.esm.js +457 -0
- package/package.json +23 -0
- package/src/assets/action/Action.tsx +31 -0
- package/src/assets/action/hooks.tsx +23 -0
- package/src/assets/action/index.ts +2 -0
- package/src/assets/collection/Collection.tsx +19 -0
- package/src/assets/collection/index.tsx +1 -0
- package/src/assets/index.tsx +5 -0
- package/src/assets/info/Info.tsx +71 -0
- package/src/assets/info/index.tsx +1 -0
- package/src/assets/input/Input.tsx +36 -0
- package/src/assets/input/hooks.tsx +277 -0
- package/src/assets/input/index.tsx +2 -0
- package/src/assets/input/types.ts +6 -0
- package/src/assets/text/Text.tsx +29 -0
- package/src/assets/text/hooks.tsx +31 -0
- package/src/assets/text/index.tsx +2 -0
- package/src/index.tsx +2 -0
- package/src/intro.stories.mdx +40 -0
- package/src/plugin.tsx +53 -0
|
@@ -0,0 +1,457 @@
|
|
|
1
|
+
import React, { useContext } from 'react';
|
|
2
|
+
import { AssetProviderPlugin } from '@player-ui/asset-provider-plugin-react';
|
|
3
|
+
import { FormControl, FormLabel, Input as Input$1, FormErrorMessage, FormHelperText, Link, Flex, Button, Text as Text$1, Box, Stack, Heading, Divider, HStack, ButtonGroup, useTheme, ChakraProvider } from '@chakra-ui/react';
|
|
4
|
+
import { isBackAction, ReferenceAssetsPlugin as ReferenceAssetsPlugin$1 } from '@player-ui/reference-assets-plugin';
|
|
5
|
+
import { Asset } from '@player-ui/react-asset';
|
|
6
|
+
import { useBeacon } from '@player-ui/beacon-plugin-react';
|
|
7
|
+
import makeClass from 'clsx';
|
|
8
|
+
import { useAssetProps } from '@player-ui/react-utils';
|
|
9
|
+
import { ChevronLeftIcon } from '@chakra-ui/icons';
|
|
10
|
+
|
|
11
|
+
var __defProp$7 = Object.defineProperty;
|
|
12
|
+
var __getOwnPropSymbols$7 = Object.getOwnPropertySymbols;
|
|
13
|
+
var __hasOwnProp$7 = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __propIsEnum$7 = Object.prototype.propertyIsEnumerable;
|
|
15
|
+
var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
16
|
+
var __spreadValues$7 = (a, b) => {
|
|
17
|
+
for (var prop in b || (b = {}))
|
|
18
|
+
if (__hasOwnProp$7.call(b, prop))
|
|
19
|
+
__defNormalProp$7(a, prop, b[prop]);
|
|
20
|
+
if (__getOwnPropSymbols$7)
|
|
21
|
+
for (var prop of __getOwnPropSymbols$7(b)) {
|
|
22
|
+
if (__propIsEnum$7.call(b, prop))
|
|
23
|
+
__defNormalProp$7(a, prop, b[prop]);
|
|
24
|
+
}
|
|
25
|
+
return a;
|
|
26
|
+
};
|
|
27
|
+
const defaultKeyStrings = [
|
|
28
|
+
"Delete",
|
|
29
|
+
"Backspace",
|
|
30
|
+
"Tab",
|
|
31
|
+
"Home",
|
|
32
|
+
"End",
|
|
33
|
+
"ArrowLeft",
|
|
34
|
+
"ArrowRight",
|
|
35
|
+
"ArrowUp",
|
|
36
|
+
"ArrowDown",
|
|
37
|
+
"Escape"
|
|
38
|
+
];
|
|
39
|
+
const getConfig = (userConfig = {}) => {
|
|
40
|
+
return __spreadValues$7({
|
|
41
|
+
liveFormat: true,
|
|
42
|
+
suppressBeacons: false,
|
|
43
|
+
quickFormatDelay: 200,
|
|
44
|
+
slowFormatDelay: 1e3,
|
|
45
|
+
slowFormatKeys: defaultKeyStrings,
|
|
46
|
+
decimalSymbol: ".",
|
|
47
|
+
prefix: "",
|
|
48
|
+
suffix: ""
|
|
49
|
+
}, userConfig);
|
|
50
|
+
};
|
|
51
|
+
const useInputBeacon = (props) => {
|
|
52
|
+
const beaconHandler = useBeacon({ element: "text_input", asset: props });
|
|
53
|
+
return (newValue) => {
|
|
54
|
+
let action = "modified";
|
|
55
|
+
if (newValue === props.value) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (newValue && !props.value) {
|
|
59
|
+
action = "added";
|
|
60
|
+
} else if (!newValue && props.value) {
|
|
61
|
+
action = "deleted";
|
|
62
|
+
}
|
|
63
|
+
beaconHandler({ action });
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
const useInputAsset = (props, config) => {
|
|
67
|
+
var _a;
|
|
68
|
+
const [localValue, setLocalValue] = React.useState((_a = props.value) != null ? _a : "");
|
|
69
|
+
const formatTimerRef = React.useRef(void 0);
|
|
70
|
+
const inputBeacon = useInputBeacon(props);
|
|
71
|
+
const {
|
|
72
|
+
liveFormat,
|
|
73
|
+
suppressBeacons,
|
|
74
|
+
quickFormatDelay,
|
|
75
|
+
slowFormatDelay,
|
|
76
|
+
slowFormatKeys,
|
|
77
|
+
decimalSymbol,
|
|
78
|
+
prefix,
|
|
79
|
+
suffix
|
|
80
|
+
} = getConfig(config);
|
|
81
|
+
function clearPending() {
|
|
82
|
+
if (formatTimerRef.current) {
|
|
83
|
+
clearTimeout(formatTimerRef.current);
|
|
84
|
+
formatTimerRef.current = void 0;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
function getFormatDelaySpeed(e) {
|
|
88
|
+
const key = slowFormatKeys.every((k) => typeof k === "number") ? e.which : e.key;
|
|
89
|
+
return slowFormatKeys.includes(key) ? slowFormatDelay : quickFormatDelay;
|
|
90
|
+
}
|
|
91
|
+
function handleAffixOnFocus(target) {
|
|
92
|
+
let val = target.value;
|
|
93
|
+
if (suffix)
|
|
94
|
+
val = val.substring(0, val.indexOf(suffix));
|
|
95
|
+
if (prefix && !val.includes(prefix)) {
|
|
96
|
+
val = `${prefix}${val}`;
|
|
97
|
+
}
|
|
98
|
+
return val;
|
|
99
|
+
}
|
|
100
|
+
function handlePrefixEdgeCases(e) {
|
|
101
|
+
const target = e.target;
|
|
102
|
+
const start = target.selectionStart;
|
|
103
|
+
const end = target.selectionEnd;
|
|
104
|
+
const pl = prefix.length;
|
|
105
|
+
const atStart = start === pl;
|
|
106
|
+
const atEnd = end === pl;
|
|
107
|
+
if (start && end && start < pl) {
|
|
108
|
+
e.preventDefault();
|
|
109
|
+
target.setSelectionRange(pl, end - start + pl);
|
|
110
|
+
} else if (e.key === "ArrowLeft" && atStart || e.key === "Backspace" && atStart && atEnd || e.key === "Home") {
|
|
111
|
+
e.preventDefault();
|
|
112
|
+
target.setSelectionRange(prefix.length, prefix.length);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function formatValueWithAffix(value) {
|
|
116
|
+
if (!value)
|
|
117
|
+
return "";
|
|
118
|
+
return `${prefix}${value}${suffix}`;
|
|
119
|
+
}
|
|
120
|
+
const onKeyDownHandler = (currentValue) => {
|
|
121
|
+
var _a2;
|
|
122
|
+
const symbolPosition = currentValue.indexOf(decimalSymbol);
|
|
123
|
+
const newValue = (_a2 = props.format(currentValue)) != null ? _a2 : "";
|
|
124
|
+
const newSymbolPosition = newValue.indexOf(decimalSymbol);
|
|
125
|
+
if ((symbolPosition === -1 || symbolPosition === 0) && newSymbolPosition > 0) {
|
|
126
|
+
return {
|
|
127
|
+
newValue: newValue.includes(prefix) ? `${newValue}` : `${prefix}${newValue}`,
|
|
128
|
+
newCursorPosition: newValue.includes(prefix) ? newSymbolPosition : newSymbolPosition + prefix.length
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
return {
|
|
132
|
+
newValue: newValue.includes(prefix) ? `${newValue}` : `${prefix}${newValue}`
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
const onBlur = (e) => {
|
|
136
|
+
var _a2;
|
|
137
|
+
clearPending();
|
|
138
|
+
const formatted = (_a2 = prefix ? e.target.value.replace(prefix, "") : props.format(e.target.value)) != null ? _a2 : "";
|
|
139
|
+
if (formatted) {
|
|
140
|
+
props.set(formatted);
|
|
141
|
+
setLocalValue(formatValueWithAffix(formatted));
|
|
142
|
+
} else {
|
|
143
|
+
props.set("");
|
|
144
|
+
setLocalValue("");
|
|
145
|
+
}
|
|
146
|
+
if (!suppressBeacons) {
|
|
147
|
+
inputBeacon(formatted);
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
const onChange = (e) => {
|
|
151
|
+
setLocalValue(e.target.value);
|
|
152
|
+
};
|
|
153
|
+
const onKeyDown = (e) => {
|
|
154
|
+
clearPending();
|
|
155
|
+
if (prefix)
|
|
156
|
+
handlePrefixEdgeCases(e);
|
|
157
|
+
const target = e.target;
|
|
158
|
+
if (liveFormat) {
|
|
159
|
+
formatTimerRef.current = setTimeout(() => {
|
|
160
|
+
var _a2, _b;
|
|
161
|
+
const cursorPosition = target.selectionStart;
|
|
162
|
+
const currentValue = target.value;
|
|
163
|
+
if (cursorPosition !== currentValue.length) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
const obj = onKeyDownHandler(currentValue);
|
|
167
|
+
setLocalValue(obj.newValue);
|
|
168
|
+
target.selectionStart = (_a2 = obj.newCursorPosition) != null ? _a2 : target.selectionStart;
|
|
169
|
+
target.selectionEnd = (_b = obj.newCursorPosition) != null ? _b : target.selectionEnd;
|
|
170
|
+
}, getFormatDelaySpeed(e));
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
const onFocus = (e) => {
|
|
174
|
+
const target = e.target;
|
|
175
|
+
const inputEmpty = target.value === "";
|
|
176
|
+
if (!inputEmpty && suffix || inputEmpty && prefix) {
|
|
177
|
+
setLocalValue(handleAffixOnFocus(target));
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
const propsValue = props.value;
|
|
181
|
+
React.useEffect(() => {
|
|
182
|
+
setLocalValue(formatValueWithAffix(propsValue));
|
|
183
|
+
}, [propsValue]);
|
|
184
|
+
React.useEffect(() => clearPending, []);
|
|
185
|
+
return {
|
|
186
|
+
onBlur,
|
|
187
|
+
onChange,
|
|
188
|
+
onKeyDown,
|
|
189
|
+
onFocus,
|
|
190
|
+
value: localValue
|
|
191
|
+
};
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
var __defProp$6 = Object.defineProperty;
|
|
195
|
+
var __getOwnPropSymbols$6 = Object.getOwnPropertySymbols;
|
|
196
|
+
var __hasOwnProp$6 = Object.prototype.hasOwnProperty;
|
|
197
|
+
var __propIsEnum$6 = Object.prototype.propertyIsEnumerable;
|
|
198
|
+
var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
199
|
+
var __spreadValues$6 = (a, b) => {
|
|
200
|
+
for (var prop in b || (b = {}))
|
|
201
|
+
if (__hasOwnProp$6.call(b, prop))
|
|
202
|
+
__defNormalProp$6(a, prop, b[prop]);
|
|
203
|
+
if (__getOwnPropSymbols$6)
|
|
204
|
+
for (var prop of __getOwnPropSymbols$6(b)) {
|
|
205
|
+
if (__propIsEnum$6.call(b, prop))
|
|
206
|
+
__defNormalProp$6(a, prop, b[prop]);
|
|
207
|
+
}
|
|
208
|
+
return a;
|
|
209
|
+
};
|
|
210
|
+
const Input = (props) => {
|
|
211
|
+
const { validation, label, id, note } = props;
|
|
212
|
+
const inputProps = useInputAsset(props);
|
|
213
|
+
return /* @__PURE__ */ React.createElement(FormControl, {
|
|
214
|
+
isInvalid: Boolean(validation)
|
|
215
|
+
}, label && /* @__PURE__ */ React.createElement(FormLabel, {
|
|
216
|
+
htmlFor: id
|
|
217
|
+
}, /* @__PURE__ */ React.createElement(Asset, __spreadValues$6({}, label))), /* @__PURE__ */ React.createElement(Input$1, __spreadValues$6({
|
|
218
|
+
id,
|
|
219
|
+
size: "md"
|
|
220
|
+
}, inputProps)), validation && /* @__PURE__ */ React.createElement(FormErrorMessage, null, validation.message), note && /* @__PURE__ */ React.createElement(FormHelperText, null, /* @__PURE__ */ React.createElement(Asset, __spreadValues$6({}, note))));
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
var __defProp$5 = Object.defineProperty;
|
|
224
|
+
var __defProps = Object.defineProperties;
|
|
225
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
226
|
+
var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
|
|
227
|
+
var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
|
|
228
|
+
var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
|
|
229
|
+
var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
230
|
+
var __spreadValues$5 = (a, b) => {
|
|
231
|
+
for (var prop in b || (b = {}))
|
|
232
|
+
if (__hasOwnProp$5.call(b, prop))
|
|
233
|
+
__defNormalProp$5(a, prop, b[prop]);
|
|
234
|
+
if (__getOwnPropSymbols$5)
|
|
235
|
+
for (var prop of __getOwnPropSymbols$5(b)) {
|
|
236
|
+
if (__propIsEnum$5.call(b, prop))
|
|
237
|
+
__defNormalProp$5(a, prop, b[prop]);
|
|
238
|
+
}
|
|
239
|
+
return a;
|
|
240
|
+
};
|
|
241
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
242
|
+
const TextModifierContext = React.createContext(void 0);
|
|
243
|
+
const useText = (props) => {
|
|
244
|
+
let className;
|
|
245
|
+
const modifierContext = useContext(TextModifierContext);
|
|
246
|
+
if (props.modifiers && (modifierContext == null ? void 0 : modifierContext.getClassForModifier)) {
|
|
247
|
+
className = makeClass(...props.modifiers.map(modifierContext.getClassForModifier));
|
|
248
|
+
}
|
|
249
|
+
return __spreadProps(__spreadValues$5({}, useAssetProps(props)), {
|
|
250
|
+
className,
|
|
251
|
+
children: props.value
|
|
252
|
+
});
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
var __defProp$4 = Object.defineProperty;
|
|
256
|
+
var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
|
|
257
|
+
var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
|
|
258
|
+
var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
|
|
259
|
+
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
260
|
+
var __spreadValues$4 = (a, b) => {
|
|
261
|
+
for (var prop in b || (b = {}))
|
|
262
|
+
if (__hasOwnProp$4.call(b, prop))
|
|
263
|
+
__defNormalProp$4(a, prop, b[prop]);
|
|
264
|
+
if (__getOwnPropSymbols$4)
|
|
265
|
+
for (var prop of __getOwnPropSymbols$4(b)) {
|
|
266
|
+
if (__propIsEnum$4.call(b, prop))
|
|
267
|
+
__defNormalProp$4(a, prop, b[prop]);
|
|
268
|
+
}
|
|
269
|
+
return a;
|
|
270
|
+
};
|
|
271
|
+
const getLinkModifier = (asset) => {
|
|
272
|
+
var _a;
|
|
273
|
+
return (_a = asset.modifiers) == null ? void 0 : _a.find((mod) => {
|
|
274
|
+
var _a2;
|
|
275
|
+
return mod.type === "link" && ((_a2 = mod.metaData) == null ? void 0 : _a2.ref) !== void 0;
|
|
276
|
+
});
|
|
277
|
+
};
|
|
278
|
+
const Text = (props) => {
|
|
279
|
+
const spanProps = useText(props);
|
|
280
|
+
const linkModifier = getLinkModifier(props);
|
|
281
|
+
const { value } = props;
|
|
282
|
+
if (linkModifier) {
|
|
283
|
+
return /* @__PURE__ */ React.createElement(Link, {
|
|
284
|
+
href: linkModifier.metaData.ref
|
|
285
|
+
}, value);
|
|
286
|
+
}
|
|
287
|
+
return /* @__PURE__ */ React.createElement("span", __spreadValues$4({}, spanProps), value);
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
var __defProp$3 = Object.defineProperty;
|
|
291
|
+
var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
|
|
292
|
+
var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
|
|
293
|
+
var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
|
|
294
|
+
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
295
|
+
var __spreadValues$3 = (a, b) => {
|
|
296
|
+
for (var prop in b || (b = {}))
|
|
297
|
+
if (__hasOwnProp$3.call(b, prop))
|
|
298
|
+
__defNormalProp$3(a, prop, b[prop]);
|
|
299
|
+
if (__getOwnPropSymbols$3)
|
|
300
|
+
for (var prop of __getOwnPropSymbols$3(b)) {
|
|
301
|
+
if (__propIsEnum$3.call(b, prop))
|
|
302
|
+
__defNormalProp$3(a, prop, b[prop]);
|
|
303
|
+
}
|
|
304
|
+
return a;
|
|
305
|
+
};
|
|
306
|
+
const Collection = (props) => {
|
|
307
|
+
var _a;
|
|
308
|
+
return /* @__PURE__ */ React.createElement(Flex, {
|
|
309
|
+
direction: "column",
|
|
310
|
+
gap: "5"
|
|
311
|
+
}, props.label && /* @__PURE__ */ React.createElement("h3", null, /* @__PURE__ */ React.createElement(Asset, __spreadValues$3({}, props.label))), (_a = props.values) == null ? void 0 : _a.map((a) => /* @__PURE__ */ React.createElement(Asset, __spreadValues$3({
|
|
312
|
+
key: a.asset.id
|
|
313
|
+
}, a))));
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
var __defProp$2 = Object.defineProperty;
|
|
317
|
+
var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
|
|
318
|
+
var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
|
|
319
|
+
var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
|
|
320
|
+
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
321
|
+
var __spreadValues$2 = (a, b) => {
|
|
322
|
+
for (var prop in b || (b = {}))
|
|
323
|
+
if (__hasOwnProp$2.call(b, prop))
|
|
324
|
+
__defNormalProp$2(a, prop, b[prop]);
|
|
325
|
+
if (__getOwnPropSymbols$2)
|
|
326
|
+
for (var prop of __getOwnPropSymbols$2(b)) {
|
|
327
|
+
if (__propIsEnum$2.call(b, prop))
|
|
328
|
+
__defNormalProp$2(a, prop, b[prop]);
|
|
329
|
+
}
|
|
330
|
+
return a;
|
|
331
|
+
};
|
|
332
|
+
const useAction = (props) => {
|
|
333
|
+
const { label } = props;
|
|
334
|
+
const beacon = useBeacon({
|
|
335
|
+
asset: props,
|
|
336
|
+
action: "clicked",
|
|
337
|
+
element: "button"
|
|
338
|
+
});
|
|
339
|
+
return {
|
|
340
|
+
id: props.id,
|
|
341
|
+
onClick: () => {
|
|
342
|
+
beacon();
|
|
343
|
+
props.run();
|
|
344
|
+
},
|
|
345
|
+
children: (label == null ? void 0 : label.asset) ? /* @__PURE__ */ React.createElement(Asset, __spreadValues$2({}, label == null ? void 0 : label.asset)) : null
|
|
346
|
+
};
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
var __defProp$1 = Object.defineProperty;
|
|
350
|
+
var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
|
|
351
|
+
var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
|
|
352
|
+
var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
|
|
353
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
354
|
+
var __spreadValues$1 = (a, b) => {
|
|
355
|
+
for (var prop in b || (b = {}))
|
|
356
|
+
if (__hasOwnProp$1.call(b, prop))
|
|
357
|
+
__defNormalProp$1(a, prop, b[prop]);
|
|
358
|
+
if (__getOwnPropSymbols$1)
|
|
359
|
+
for (var prop of __getOwnPropSymbols$1(b)) {
|
|
360
|
+
if (__propIsEnum$1.call(b, prop))
|
|
361
|
+
__defNormalProp$1(a, prop, b[prop]);
|
|
362
|
+
}
|
|
363
|
+
return a;
|
|
364
|
+
};
|
|
365
|
+
const Action = (props) => {
|
|
366
|
+
const { label } = props;
|
|
367
|
+
const buttonProps = useAction(props);
|
|
368
|
+
return /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement(Button, __spreadValues$1({
|
|
369
|
+
variant: isBackAction(props) ? "ghost" : "solid"
|
|
370
|
+
}, buttonProps), isBackAction(props) && /* @__PURE__ */ React.createElement(ChevronLeftIcon, null), label && /* @__PURE__ */ React.createElement(Text$1, null, /* @__PURE__ */ React.createElement(Asset, __spreadValues$1({}, label)))));
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
var __defProp = Object.defineProperty;
|
|
374
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
375
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
376
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
377
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
378
|
+
var __spreadValues = (a, b) => {
|
|
379
|
+
for (var prop in b || (b = {}))
|
|
380
|
+
if (__hasOwnProp.call(b, prop))
|
|
381
|
+
__defNormalProp(a, prop, b[prop]);
|
|
382
|
+
if (__getOwnPropSymbols)
|
|
383
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
384
|
+
if (__propIsEnum.call(b, prop))
|
|
385
|
+
__defNormalProp(a, prop, b[prop]);
|
|
386
|
+
}
|
|
387
|
+
return a;
|
|
388
|
+
};
|
|
389
|
+
const Info = (props) => {
|
|
390
|
+
var _a, _b;
|
|
391
|
+
const segmentedActions = React.useMemo(() => {
|
|
392
|
+
var _a2, _b2;
|
|
393
|
+
if (!((_a2 = props.actions) == null ? void 0 : _a2.length)) {
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
return (_b2 = props.actions) == null ? void 0 : _b2.reduce((memo, next) => {
|
|
397
|
+
memo[isBackAction(next.asset) ? "prev" : "next"].push(next);
|
|
398
|
+
return memo;
|
|
399
|
+
}, { prev: [], next: [] });
|
|
400
|
+
}, [props.actions]);
|
|
401
|
+
return /* @__PURE__ */ React.createElement(Box, {
|
|
402
|
+
minW: { base: void 0, md: "md" }
|
|
403
|
+
}, /* @__PURE__ */ React.createElement(Stack, {
|
|
404
|
+
gap: "10"
|
|
405
|
+
}, props.title && /* @__PURE__ */ React.createElement(Heading, {
|
|
406
|
+
size: "lg",
|
|
407
|
+
as: "h1"
|
|
408
|
+
}, /* @__PURE__ */ React.createElement(Asset, __spreadValues({}, props.title))), props.subTitle && /* @__PURE__ */ React.createElement(Heading, {
|
|
409
|
+
size: "md",
|
|
410
|
+
as: "h3"
|
|
411
|
+
}, /* @__PURE__ */ React.createElement(Asset, __spreadValues({}, props.subTitle))), /* @__PURE__ */ React.createElement(Box, null, props.primaryInfo && /* @__PURE__ */ React.createElement(Asset, __spreadValues({}, props.primaryInfo))), /* @__PURE__ */ React.createElement(Stack, {
|
|
412
|
+
gap: "4"
|
|
413
|
+
}, segmentedActions && /* @__PURE__ */ React.createElement(Divider, null), /* @__PURE__ */ React.createElement(HStack, {
|
|
414
|
+
justifyContent: "space-between"
|
|
415
|
+
}, /* @__PURE__ */ React.createElement(ButtonGroup, {
|
|
416
|
+
spacing: "6"
|
|
417
|
+
}, (_a = segmentedActions == null ? void 0 : segmentedActions.prev) == null ? void 0 : _a.map((a) => /* @__PURE__ */ React.createElement(Asset, __spreadValues({
|
|
418
|
+
key: a.asset.id
|
|
419
|
+
}, a)))), /* @__PURE__ */ React.createElement(ButtonGroup, {
|
|
420
|
+
spacing: "6"
|
|
421
|
+
}, (_b = segmentedActions == null ? void 0 : segmentedActions.next) == null ? void 0 : _b.map((a) => /* @__PURE__ */ React.createElement(Asset, __spreadValues({
|
|
422
|
+
key: a.asset.id
|
|
423
|
+
}, a))))))));
|
|
424
|
+
};
|
|
425
|
+
|
|
426
|
+
const OptionalChakraThemeProvider = (props) => {
|
|
427
|
+
const theme = useTheme();
|
|
428
|
+
if (theme) {
|
|
429
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, props.children);
|
|
430
|
+
}
|
|
431
|
+
return /* @__PURE__ */ React.createElement(ChakraProvider, null, props.children);
|
|
432
|
+
};
|
|
433
|
+
class ReferenceAssetsPlugin {
|
|
434
|
+
constructor() {
|
|
435
|
+
this.name = "reference-assets-web-plugin";
|
|
436
|
+
}
|
|
437
|
+
applyWeb(webplayer) {
|
|
438
|
+
webplayer.registerPlugin(new AssetProviderPlugin([
|
|
439
|
+
["input", Input],
|
|
440
|
+
["text", Text],
|
|
441
|
+
["action", Action],
|
|
442
|
+
["info", Info],
|
|
443
|
+
["collection", Collection]
|
|
444
|
+
]));
|
|
445
|
+
webplayer.hooks.webComponent.tap(this.name, (Comp) => {
|
|
446
|
+
return () => {
|
|
447
|
+
return /* @__PURE__ */ React.createElement(OptionalChakraThemeProvider, null, /* @__PURE__ */ React.createElement(Comp, null));
|
|
448
|
+
};
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
apply(player) {
|
|
452
|
+
player.registerPlugin(new ReferenceAssetsPlugin$1());
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
export { Action, Collection, Info, Input, ReferenceAssetsPlugin, Text, TextModifierContext, getConfig, getLinkModifier, useAction, useInputAsset, useInputBeacon, useText };
|
|
457
|
+
//# sourceMappingURL=index.esm.js.map
|
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@player-ui/reference-assets-plugin-react",
|
|
3
|
+
"version": "0.0.1-next.1",
|
|
4
|
+
"private": false,
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"registry": "https://registry.npmjs.org"
|
|
7
|
+
},
|
|
8
|
+
"peerDependencies": {
|
|
9
|
+
"@types/node": "^16.11.12",
|
|
10
|
+
"@player-ui/binding-grammar": "0.0.1-next.1"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@player-ui/binding-grammar": "0.0.1-next.1",
|
|
14
|
+
"@player-ui/partial-match-registry": "0.0.1-next.1",
|
|
15
|
+
"clsx": "^1.1.1",
|
|
16
|
+
"@chakra-ui/react": "^1.7.3",
|
|
17
|
+
"@chakra-ui/icons": "^1.1.1",
|
|
18
|
+
"@babel/runtime": "7.15.4"
|
|
19
|
+
},
|
|
20
|
+
"main": "dist/index.cjs.js",
|
|
21
|
+
"module": "dist/index.esm.js",
|
|
22
|
+
"typings": "dist/index.d.ts"
|
|
23
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Asset } from '@player-ui/react-asset';
|
|
3
|
+
import { Button, Text } from '@chakra-ui/react';
|
|
4
|
+
import { ChevronLeftIcon } from '@chakra-ui/icons';
|
|
5
|
+
import type { TransformedAction } from '@player-ui/reference-assets-plugin';
|
|
6
|
+
import { isBackAction } from '@player-ui/reference-assets-plugin';
|
|
7
|
+
import { useAction } from './hooks';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* An action that a user can take
|
|
11
|
+
*/
|
|
12
|
+
export const Action = (props: TransformedAction) => {
|
|
13
|
+
const { label } = props;
|
|
14
|
+
const buttonProps = useAction(props);
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
<div>
|
|
18
|
+
<Button
|
|
19
|
+
variant={isBackAction(props) ? 'ghost' : 'solid'}
|
|
20
|
+
{...buttonProps}
|
|
21
|
+
>
|
|
22
|
+
{isBackAction(props) && <ChevronLeftIcon />}
|
|
23
|
+
{label && (
|
|
24
|
+
<Text>
|
|
25
|
+
<Asset {...label} />
|
|
26
|
+
</Text>
|
|
27
|
+
)}
|
|
28
|
+
</Button>
|
|
29
|
+
</div>
|
|
30
|
+
);
|
|
31
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Asset } from '@player-ui/react-asset';
|
|
3
|
+
import { useBeacon } from '@player-ui/beacon-plugin-react';
|
|
4
|
+
import type { TransformedAction } from '@player-ui/reference-assets-plugin';
|
|
5
|
+
|
|
6
|
+
/** Hook to get all the props for a button */
|
|
7
|
+
export const useAction = (props: TransformedAction) => {
|
|
8
|
+
const { label } = props;
|
|
9
|
+
const beacon = useBeacon({
|
|
10
|
+
asset: props,
|
|
11
|
+
action: 'clicked',
|
|
12
|
+
element: 'button',
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
return {
|
|
16
|
+
id: props.id,
|
|
17
|
+
onClick: () => {
|
|
18
|
+
beacon();
|
|
19
|
+
props.run();
|
|
20
|
+
},
|
|
21
|
+
children: label?.asset ? <Asset {...label?.asset} /> : null,
|
|
22
|
+
} as const;
|
|
23
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Flex } from '@chakra-ui/react';
|
|
3
|
+
import { Asset } from '@player-ui/react-asset';
|
|
4
|
+
import type { CollectionAsset } from '@player-ui/reference-assets-plugin';
|
|
5
|
+
|
|
6
|
+
export const Collection = (props: CollectionAsset) => {
|
|
7
|
+
return (
|
|
8
|
+
<Flex direction="column" gap="5">
|
|
9
|
+
{props.label && (
|
|
10
|
+
<h3>
|
|
11
|
+
<Asset {...props.label} />
|
|
12
|
+
</h3>
|
|
13
|
+
)}
|
|
14
|
+
{props.values?.map((a) => (
|
|
15
|
+
<Asset key={a.asset.id} {...a} />
|
|
16
|
+
))}
|
|
17
|
+
</Flex>
|
|
18
|
+
);
|
|
19
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Collection';
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type {
|
|
3
|
+
ActionAsset,
|
|
4
|
+
InfoAsset,
|
|
5
|
+
} from '@player-ui/reference-assets-plugin';
|
|
6
|
+
import { isBackAction } from '@player-ui/reference-assets-plugin';
|
|
7
|
+
import { Asset } from '@player-ui/react-asset';
|
|
8
|
+
import {
|
|
9
|
+
ButtonGroup,
|
|
10
|
+
Box,
|
|
11
|
+
Heading,
|
|
12
|
+
Divider,
|
|
13
|
+
Stack,
|
|
14
|
+
HStack,
|
|
15
|
+
} from '@chakra-ui/react';
|
|
16
|
+
import type { AssetWrapper } from '@player-ui/react';
|
|
17
|
+
|
|
18
|
+
/** The info view type is used to show information to the user */
|
|
19
|
+
export const Info = (props: InfoAsset) => {
|
|
20
|
+
const segmentedActions = React.useMemo(() => {
|
|
21
|
+
if (!props.actions?.length) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return props.actions?.reduce(
|
|
26
|
+
(memo, next) => {
|
|
27
|
+
memo[isBackAction(next.asset as ActionAsset) ? 'prev' : 'next'].push(
|
|
28
|
+
next as AssetWrapper<ActionAsset>
|
|
29
|
+
);
|
|
30
|
+
return memo;
|
|
31
|
+
},
|
|
32
|
+
{ prev: [], next: [] } as {
|
|
33
|
+
prev: Array<AssetWrapper<ActionAsset>>;
|
|
34
|
+
next: Array<AssetWrapper<ActionAsset>>;
|
|
35
|
+
}
|
|
36
|
+
);
|
|
37
|
+
}, [props.actions]);
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<Box minW={{ base: undefined, md: 'md' }}>
|
|
41
|
+
<Stack gap="10">
|
|
42
|
+
{props.title && (
|
|
43
|
+
<Heading size="lg" as="h1">
|
|
44
|
+
<Asset {...props.title} />
|
|
45
|
+
</Heading>
|
|
46
|
+
)}
|
|
47
|
+
{props.subTitle && (
|
|
48
|
+
<Heading size="md" as="h3">
|
|
49
|
+
<Asset {...props.subTitle} />
|
|
50
|
+
</Heading>
|
|
51
|
+
)}
|
|
52
|
+
<Box>{props.primaryInfo && <Asset {...props.primaryInfo} />}</Box>
|
|
53
|
+
<Stack gap="4">
|
|
54
|
+
{segmentedActions && <Divider />}
|
|
55
|
+
<HStack justifyContent="space-between">
|
|
56
|
+
<ButtonGroup spacing="6">
|
|
57
|
+
{segmentedActions?.prev?.map((a) => (
|
|
58
|
+
<Asset key={a.asset.id} {...a} />
|
|
59
|
+
))}
|
|
60
|
+
</ButtonGroup>
|
|
61
|
+
<ButtonGroup spacing="6">
|
|
62
|
+
{segmentedActions?.next?.map((a) => (
|
|
63
|
+
<Asset key={a.asset.id} {...a} />
|
|
64
|
+
))}
|
|
65
|
+
</ButtonGroup>
|
|
66
|
+
</HStack>
|
|
67
|
+
</Stack>
|
|
68
|
+
</Stack>
|
|
69
|
+
</Box>
|
|
70
|
+
);
|
|
71
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Info';
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Asset } from '@player-ui/react-asset';
|
|
3
|
+
import type { TransformedInput } from '@player-ui/reference-assets-plugin';
|
|
4
|
+
import {
|
|
5
|
+
Input as ChakraInput,
|
|
6
|
+
FormControl,
|
|
7
|
+
FormLabel,
|
|
8
|
+
FormErrorMessage,
|
|
9
|
+
FormHelperText,
|
|
10
|
+
} from '@chakra-ui/react';
|
|
11
|
+
import { useInputAsset } from './hooks';
|
|
12
|
+
|
|
13
|
+
/** An Input */
|
|
14
|
+
export const Input = (props: TransformedInput) => {
|
|
15
|
+
const { validation, label, id, note } = props;
|
|
16
|
+
const inputProps = useInputAsset(props);
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<FormControl isInvalid={Boolean(validation)}>
|
|
20
|
+
{label && (
|
|
21
|
+
<FormLabel htmlFor={id}>
|
|
22
|
+
<Asset {...label} />
|
|
23
|
+
</FormLabel>
|
|
24
|
+
)}
|
|
25
|
+
<ChakraInput id={id} size="md" {...inputProps} />
|
|
26
|
+
{validation && <FormErrorMessage>{validation.message}</FormErrorMessage>}
|
|
27
|
+
{note && (
|
|
28
|
+
<FormHelperText>
|
|
29
|
+
<Asset {...note} />
|
|
30
|
+
</FormHelperText>
|
|
31
|
+
)}
|
|
32
|
+
</FormControl>
|
|
33
|
+
);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export default Input;
|