@micromag/core 0.3.111 → 0.3.117
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/es/components.js +178 -115
- package/es/hooks.js +25 -2
- package/es/index.js +2 -0
- package/es/utils.js +138 -1
- package/lib/components.js +195 -113
- package/lib/hooks.js +24 -0
- package/lib/index.js +2 -0
- package/lib/utils.js +140 -0
- package/package.json +2 -2
package/es/hooks.js
CHANGED
|
@@ -4,7 +4,7 @@ import { useIntl } from 'react-intl';
|
|
|
4
4
|
import isString from 'lodash/isString';
|
|
5
5
|
import dayjs from 'dayjs';
|
|
6
6
|
import { EventsManager, MediasParser, StoryParser, ThemeParser } from '@micromag/core';
|
|
7
|
-
import { createUseEvent } from '@micromag/core/utils';
|
|
7
|
+
import { createUseEvent, getMediaFilesAsArray } from '@micromag/core/utils';
|
|
8
8
|
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
9
9
|
import { useForm as useForm$1 } from '@folklore/forms';
|
|
10
10
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
@@ -1053,6 +1053,29 @@ var useMediasParser = function useMediasParser() {
|
|
|
1053
1053
|
};
|
|
1054
1054
|
};
|
|
1055
1055
|
|
|
1056
|
+
function useMediaThumbnail(media) {
|
|
1057
|
+
var file = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
1058
|
+
|
|
1059
|
+
var _ref = media || {},
|
|
1060
|
+
_ref$thumbnail_url = _ref.thumbnail_url,
|
|
1061
|
+
defaultThumbnailUrl = _ref$thumbnail_url === void 0 ? null : _ref$thumbnail_url,
|
|
1062
|
+
_ref$files = _ref.files,
|
|
1063
|
+
files = _ref$files === void 0 ? null : _ref$files;
|
|
1064
|
+
|
|
1065
|
+
var thumbnailUrl = useMemo(function () {
|
|
1066
|
+
var filesArray = getMediaFilesAsArray(files) || [];
|
|
1067
|
+
|
|
1068
|
+
var _ref2 = (file !== null ? filesArray.find(function (_ref3) {
|
|
1069
|
+
var handle = _ref3.handle;
|
|
1070
|
+
return handle === file;
|
|
1071
|
+
}) || null : null) || {},
|
|
1072
|
+
url = _ref2.url;
|
|
1073
|
+
|
|
1074
|
+
return url || defaultThumbnailUrl;
|
|
1075
|
+
}, [files, file, defaultThumbnailUrl]);
|
|
1076
|
+
return thumbnailUrl;
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1056
1079
|
var useParsedStory = function useParsedStory(story) {
|
|
1057
1080
|
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
1058
1081
|
_ref$disabled = _ref.disabled,
|
|
@@ -1566,4 +1589,4 @@ var useTrackMedia = function useTrackMedia() {
|
|
|
1566
1589
|
var eventsManager = typeof window !== 'undefined' ? new EventsManager(window) : null;
|
|
1567
1590
|
var useWindowEvent = createUseEvent(eventsManager);
|
|
1568
1591
|
|
|
1569
|
-
export { getObserver, useAnimationFrame, useDocumentEvent, useForm, useFormTransition, useFormattedDate, useFormattedTime, useFullscreen, useIntersectionObserver, useIsVisible, useLoadedFonts, useLongPress, useMediaApi, useMediasParser, useObserver, useParsedStory, useResizeObserver, useScreenSizeFromElement, useScreenSizeFromWindow, useSwipe, useThemeParser, useTrackEvent, useTrackMedia, useTrackScreenEvent, useTrackScreenMedia, useTrackScreenView, useWindowEvent };
|
|
1592
|
+
export { getObserver, useAnimationFrame, useDocumentEvent, useForm, useFormTransition, useFormattedDate, useFormattedTime, useFullscreen, useIntersectionObserver, useIsVisible, useLoadedFonts, useLongPress, useMediaApi, useMediaThumbnail, useMediasParser, useObserver, useParsedStory, useResizeObserver, useScreenSizeFromElement, useScreenSizeFromWindow, useSwipe, useThemeParser, useTrackEvent, useTrackMedia, useTrackScreenEvent, useTrackScreenMedia, useTrackScreenView, useWindowEvent };
|
package/es/index.js
CHANGED
|
@@ -14,6 +14,8 @@ import _createSuper from '@babel/runtime/helpers/createSuper';
|
|
|
14
14
|
import EventEmitter from 'wolfy87-eventemitter';
|
|
15
15
|
import 'lodash/isNumber';
|
|
16
16
|
import 'param-case';
|
|
17
|
+
import '@babel/runtime/helpers/asyncToGenerator';
|
|
18
|
+
import '@babel/runtime/regenerator';
|
|
17
19
|
import 'react';
|
|
18
20
|
import isString from 'lodash/isString';
|
|
19
21
|
import 'tinycolor2';
|
package/es/utils.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import isNumber from 'lodash/isNumber';
|
|
2
2
|
import { paramCase } from 'param-case';
|
|
3
|
+
import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
|
|
4
|
+
import _regeneratorRuntime from '@babel/runtime/regenerator';
|
|
3
5
|
import isObject from 'lodash/isObject';
|
|
4
6
|
import { useEffect } from 'react';
|
|
5
7
|
import isString from 'lodash/isString';
|
|
@@ -20,6 +22,141 @@ var convertStyleToString = function convertStyleToString(style) {
|
|
|
20
22
|
}).join('\n') : '';
|
|
21
23
|
};
|
|
22
24
|
|
|
25
|
+
/*! clipboard-copy. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
|
26
|
+
// @todo vendoring this: https://github.com/feross/clipboard-copy/blob/master/index.js
|
|
27
|
+
// we might want to add that to the npm deps and just use it?
|
|
28
|
+
function makeError() {
|
|
29
|
+
return new DOMException('The request is not allowed', 'NotAllowedError');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function copyClipboardApi(_x) {
|
|
33
|
+
return _copyClipboardApi.apply(this, arguments);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function _copyClipboardApi() {
|
|
37
|
+
_copyClipboardApi = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(text) {
|
|
38
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
39
|
+
while (1) {
|
|
40
|
+
switch (_context.prev = _context.next) {
|
|
41
|
+
case 0:
|
|
42
|
+
if (navigator.clipboard) {
|
|
43
|
+
_context.next = 2;
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
throw makeError();
|
|
48
|
+
|
|
49
|
+
case 2:
|
|
50
|
+
return _context.abrupt("return", navigator.clipboard.writeText(text));
|
|
51
|
+
|
|
52
|
+
case 3:
|
|
53
|
+
case "end":
|
|
54
|
+
return _context.stop();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}, _callee);
|
|
58
|
+
}));
|
|
59
|
+
return _copyClipboardApi.apply(this, arguments);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function copyExecCommand(_x2) {
|
|
63
|
+
return _copyExecCommand.apply(this, arguments);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function _copyExecCommand() {
|
|
67
|
+
_copyExecCommand = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(text) {
|
|
68
|
+
var span, selection, range, success;
|
|
69
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
70
|
+
while (1) {
|
|
71
|
+
switch (_context2.prev = _context2.next) {
|
|
72
|
+
case 0:
|
|
73
|
+
// Put the text to copy into a <span>
|
|
74
|
+
span = document.createElement('span');
|
|
75
|
+
span.textContent = text; // Preserve consecutive spaces and newlines
|
|
76
|
+
|
|
77
|
+
span.style.whiteSpace = 'pre';
|
|
78
|
+
span.style.webkitUserSelect = 'auto';
|
|
79
|
+
span.style.userSelect = 'all'; // Add the <span> to the page
|
|
80
|
+
|
|
81
|
+
document.body.appendChild(span); // Make a selection object representing the range of text selected by the user
|
|
82
|
+
|
|
83
|
+
selection = window.getSelection();
|
|
84
|
+
range = window.document.createRange();
|
|
85
|
+
selection.removeAllRanges();
|
|
86
|
+
range.selectNode(span);
|
|
87
|
+
selection.addRange(range); // Copy text to the clipboard
|
|
88
|
+
|
|
89
|
+
success = false;
|
|
90
|
+
|
|
91
|
+
try {
|
|
92
|
+
success = window.document.execCommand('copy');
|
|
93
|
+
} finally {
|
|
94
|
+
// Cleanup
|
|
95
|
+
selection.removeAllRanges();
|
|
96
|
+
window.document.body.removeChild(span);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (success) {
|
|
100
|
+
_context2.next = 15;
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
throw makeError();
|
|
105
|
+
|
|
106
|
+
case 15:
|
|
107
|
+
case "end":
|
|
108
|
+
return _context2.stop();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}, _callee2);
|
|
112
|
+
}));
|
|
113
|
+
return _copyExecCommand.apply(this, arguments);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function copyToClipboard(_x3) {
|
|
117
|
+
return _copyToClipboard.apply(this, arguments);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function _copyToClipboard() {
|
|
121
|
+
_copyToClipboard = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(text) {
|
|
122
|
+
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
123
|
+
while (1) {
|
|
124
|
+
switch (_context3.prev = _context3.next) {
|
|
125
|
+
case 0:
|
|
126
|
+
_context3.prev = 0;
|
|
127
|
+
_context3.next = 3;
|
|
128
|
+
return copyClipboardApi(text);
|
|
129
|
+
|
|
130
|
+
case 3:
|
|
131
|
+
_context3.next = 15;
|
|
132
|
+
break;
|
|
133
|
+
|
|
134
|
+
case 5:
|
|
135
|
+
_context3.prev = 5;
|
|
136
|
+
_context3.t0 = _context3["catch"](0);
|
|
137
|
+
_context3.prev = 7;
|
|
138
|
+
_context3.next = 10;
|
|
139
|
+
return copyExecCommand(text);
|
|
140
|
+
|
|
141
|
+
case 10:
|
|
142
|
+
_context3.next = 15;
|
|
143
|
+
break;
|
|
144
|
+
|
|
145
|
+
case 12:
|
|
146
|
+
_context3.prev = 12;
|
|
147
|
+
_context3.t1 = _context3["catch"](7);
|
|
148
|
+
throw _context3.t1 || _context3.t0 || makeError();
|
|
149
|
+
|
|
150
|
+
case 15:
|
|
151
|
+
case "end":
|
|
152
|
+
return _context3.stop();
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}, _callee3, null, [[0, 5], [7, 12]]);
|
|
156
|
+
}));
|
|
157
|
+
return _copyToClipboard.apply(this, arguments);
|
|
158
|
+
}
|
|
159
|
+
|
|
23
160
|
var createNullableOnChange = function createNullableOnChange() {
|
|
24
161
|
var onChange = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
25
162
|
return function (newValue) {
|
|
@@ -852,4 +989,4 @@ var getContrastingColor = function getContrastingColor(backgroundColor) {
|
|
|
852
989
|
return tinycolor(color).spin(30).toString();
|
|
853
990
|
};
|
|
854
991
|
|
|
855
|
-
export { convertStyleToString, createNullableOnChange, createUseEvent, getColorAsString, getComponentFromName, getContrastingColor, getDeviceScreens, getDisplayName, getFieldByName, getFieldFromPath, getFileName, getFontFamily as getFontFamilyFromFont, getGridLayoutName, largestRemainderRound as getLargestRemainderRound, getLayersFromBackground, getLayoutParts, getMediaFilesAsArray, getOptimalImageUrl, getScreenExtraField, getSecondsFromTime, getShadowCoords, getStyleFromBorder, getStyleFromBox, getStyleFromColor, getStyleFromContainer, getStyleFromHighlight, getStyleFromImage, getStyleFromLink, getStyleFromMargin, getStyleFromText, isImageFilled, isIos, isTextFilled$1 as isLabelFilled, isMessage, isTextFilled, isValidUrl, schemaId, setValue as setFieldValue, slug, unique, validateFields };
|
|
992
|
+
export { convertStyleToString, copyToClipboard, createNullableOnChange, createUseEvent, getColorAsString, getComponentFromName, getContrastingColor, getDeviceScreens, getDisplayName, getFieldByName, getFieldFromPath, getFileName, getFontFamily as getFontFamilyFromFont, getGridLayoutName, largestRemainderRound as getLargestRemainderRound, getLayersFromBackground, getLayoutParts, getMediaFilesAsArray, getOptimalImageUrl, getScreenExtraField, getSecondsFromTime, getShadowCoords, getStyleFromBorder, getStyleFromBox, getStyleFromColor, getStyleFromContainer, getStyleFromHighlight, getStyleFromImage, getStyleFromLink, getStyleFromMargin, getStyleFromText, isImageFilled, isIos, isTextFilled$1 as isLabelFilled, isMessage, isTextFilled, isValidUrl, schemaId, setValue as setFieldValue, slug, unique, validateFields };
|