@hero-design/rn 8.108.2 → 8.109.0

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/lib/index.js CHANGED
@@ -28393,9 +28393,11 @@ var ToolbarEvents;
28393
28393
  ToolbarEvents["HeadingOne"] = "heading-one";
28394
28394
  ToolbarEvents["HeadingTwo"] = "heading-two";
28395
28395
  })(ToolbarEvents || (ToolbarEvents = {}));
28396
-
28397
- var emitter = new events.EventEmitter();
28398
- emitter.setMaxListeners(20);
28396
+ var EditorEvents;
28397
+ (function (EditorEvents) {
28398
+ EditorEvents["EditorFocus"] = "editor-focus";
28399
+ EditorEvents["EditorBlur"] = "editor-blur";
28400
+ })(EditorEvents || (EditorEvents = {}));
28399
28401
 
28400
28402
  var StyledToolbarButton = index$c(reactNative.TouchableOpacity)(function (_ref) {
28401
28403
  var theme = _ref.theme,
@@ -28441,6 +28443,40 @@ var on = function on(emitter, eventName, listener) {
28441
28443
  };
28442
28444
  };
28443
28445
 
28446
+ var emitter = new events.EventEmitter();
28447
+ emitter.setMaxListeners(20);
28448
+
28449
+ /**
28450
+ * Hook to subscribe to events for a rich text editor
28451
+ * @param editorName - The name of the editor to subscribe to events for
28452
+ * @returns An object with two functions: emitEvent and subscribeToEvents
28453
+ * @example
28454
+ * const { emitEvent, subscribeToEvents } = useRichTextEditorEvents('editorName');
28455
+ * subscribeToEvents(EditorEvents.EditorFocus, () => {
28456
+ * console.log('Editor focused');
28457
+ * });
28458
+ * emitEvent({ type: EditorEvents.EditorFocus, data: null });
28459
+ */
28460
+ var useRichTextEditorEvents = function useRichTextEditorEvents(editorName) {
28461
+ var normalizeEventName = React.useCallback(function (event) {
28462
+ return "".concat(editorName, "/").concat(event);
28463
+ }, [editorName]);
28464
+ var subscribeToEvents = React.useCallback(function (eventName, onEvent) {
28465
+ return on(emitter, normalizeEventName(eventName), function (eventData) {
28466
+ onEvent(eventData);
28467
+ });
28468
+ }, [normalizeEventName]);
28469
+ var emitEvent = React.useCallback(function (_ref) {
28470
+ var type = _ref.type,
28471
+ data = _ref.data;
28472
+ emit(emitter, normalizeEventName(type), data);
28473
+ }, [normalizeEventName]);
28474
+ return {
28475
+ emitEvent: emitEvent,
28476
+ subscribeToEvents: subscribeToEvents
28477
+ };
28478
+ };
28479
+
28444
28480
  var ToolbarButton = function ToolbarButton(_ref) {
28445
28481
  var icon = _ref.icon,
28446
28482
  onPress = _ref.onPress,
@@ -28510,14 +28546,14 @@ var EditorToolbar = function EditorToolbar(_ref2) {
28510
28546
  _useState4 = _slicedToArray(_useState3, 2),
28511
28547
  toolbarButtonArray = _useState4[0],
28512
28548
  setToolbarButtonArray = _useState4[1];
28513
- var normalizeEventName = React.useCallback(function (event) {
28514
- return "".concat(name, "/").concat(event);
28515
- }, [name]);
28549
+ var _useRichTextEditorEve = useRichTextEditorEvents(name),
28550
+ emitEvent = _useRichTextEditorEve.emitEvent,
28551
+ subscribeToEvents = _useRichTextEditorEve.subscribeToEvents;
28516
28552
  React.useEffect(function () {
28517
- var removeFocusListener = on(emitter, normalizeEventName('editor-focus'), function () {
28553
+ var removeFocusListener = subscribeToEvents(EditorEvents.EditorFocus, function () {
28518
28554
  return setShow(true);
28519
28555
  });
28520
- var removeBlurListener = on(emitter, normalizeEventName('editor-blur'), function () {
28556
+ var removeBlurListener = subscribeToEvents(EditorEvents.EditorBlur, function () {
28521
28557
  return setShow(false);
28522
28558
  });
28523
28559
  return function () {
@@ -28560,7 +28596,10 @@ var EditorToolbar = function EditorToolbar(_ref2) {
28560
28596
  icon: config.icon,
28561
28597
  onPress: function onPress() {
28562
28598
  toggleToolbarButton(button);
28563
- emit(emitter, normalizeEventName(config.eventName), null);
28599
+ emitEvent({
28600
+ type: config.eventName,
28601
+ data: null
28602
+ });
28564
28603
  },
28565
28604
  selected: button.selected
28566
28605
  });
@@ -28582,7 +28621,7 @@ var isEmptyString = function isEmptyString(s) {
28582
28621
  var MentionList = function MentionList(_ref) {
28583
28622
  var eventPrefix = _ref.name,
28584
28623
  render = _ref.render;
28585
- var theme = useTheme$1();
28624
+ var theme = useTheme();
28586
28625
  var _useState = React.useState(''),
28587
28626
  _useState2 = _slicedToArray(_useState, 2),
28588
28627
  search = _useState2[0],
@@ -28615,7 +28654,7 @@ var MentionList = function MentionList(_ref) {
28615
28654
  var highlighted = options.highlighted,
28616
28655
  meta = options.meta;
28617
28656
  var highlightStyle = {
28618
- color: theme.colors.secondary,
28657
+ color: theme.colors.primary,
28619
28658
  borderRadius: theme.__hd__.richTextEditor.radii.mention,
28620
28659
  padding: highlighted ? theme.__hd__.richTextEditor.space.mention : 0,
28621
28660
  background: highlighted ? theme.colors.highlightedSurface : 'transparent',
@@ -47340,8 +47379,7 @@ var StyledWebView = index$c(reactNativeWebview.WebView)(function (_ref2) {
47340
47379
  minHeight: theme.__hd__.richTextEditor.sizes.editorMinHeight,
47341
47380
  backgroundColor: 'transparent',
47342
47381
  textAlignVertical: 'center',
47343
- fontSize: theme.__hd__.textInput.fontSizes.text,
47344
- marginHorizontal: theme.__hd__.textInput.space.inputHorizontalMargin
47382
+ fontSize: theme.__hd__.textInput.fontSizes.text
47345
47383
  };
47346
47384
  });
47347
47385
 
@@ -47353,13 +47391,13 @@ var postMessage = function postMessage(element, message) {
47353
47391
  element.injectJavaScript("window.postMessage(".concat(messageString, ", '*');"));
47354
47392
  };
47355
47393
 
47356
- var defaultValue = [{
47394
+ var defaultValue$1 = [{
47357
47395
  type: 'paragraph',
47358
47396
  children: [{
47359
47397
  text: ''
47360
47398
  }]
47361
47399
  }];
47362
- var RichTextEditor = function RichTextEditor(_ref) {
47400
+ var BaseRichTextEditor = function BaseRichTextEditor(_ref) {
47363
47401
  var _ref$autoFocus = _ref.autoFocus,
47364
47402
  autoFocus = _ref$autoFocus === void 0 ? true : _ref$autoFocus,
47365
47403
  name = _ref.name,
@@ -47367,18 +47405,15 @@ var RichTextEditor = function RichTextEditor(_ref) {
47367
47405
  placeholder = _ref$placeholder === void 0 ? '' : _ref$placeholder,
47368
47406
  onChange = _ref.onChange,
47369
47407
  onCursorChange = _ref.onCursorChange,
47370
- _ref$error = _ref.error,
47371
- error = _ref$error === void 0 ? '' : _ref$error,
47372
47408
  _ref$style = _ref.style,
47373
47409
  style = _ref$style === void 0 ? {} : _ref$style,
47374
- label = _ref.label,
47375
- helpText = _ref.helpText,
47376
- required = _ref.required,
47377
47410
  testID = _ref.testID,
47378
- forwardedRef = _ref.forwardedRef,
47411
+ editorRef = _ref.editorRef,
47379
47412
  _ref$value = _ref.value,
47380
- value = _ref$value === void 0 ? defaultValue : _ref$value;
47381
- var theme = useTheme$1();
47413
+ value = _ref$value === void 0 ? defaultValue$1 : _ref$value,
47414
+ onFocus = _ref.onFocus,
47415
+ onBlur = _ref.onBlur;
47416
+ var theme = useTheme();
47382
47417
  var webview = React.useRef(null);
47383
47418
  var _useState = React.useState(),
47384
47419
  _useState2 = _slicedToArray(_useState, 2),
@@ -47388,18 +47423,6 @@ var RichTextEditor = function RichTextEditor(_ref) {
47388
47423
  _useState4 = _slicedToArray(_useState3, 2),
47389
47424
  isFocused = _useState4[0],
47390
47425
  setIsFocused = _useState4[1];
47391
- var isEmptyValue = React.useMemo(function () {
47392
- return libExports.isEmptyContent(value);
47393
- }, [value]);
47394
- var state = React.useMemo(function () {
47395
- if (error) {
47396
- return 'error';
47397
- }
47398
- if (isEmptyValue) {
47399
- return 'filled';
47400
- }
47401
- return 'default';
47402
- }, [isFocused, error, isEmptyValue]);
47403
47426
  var normalizeEventName = function normalizeEventName(event) {
47404
47427
  return "".concat(name, "/").concat(event);
47405
47428
  };
@@ -47408,45 +47431,6 @@ var RichTextEditor = function RichTextEditor(_ref) {
47408
47431
  postMessage(webview.current, message);
47409
47432
  }
47410
47433
  };
47411
- var _React$useState = React__namespace.default.useState({
47412
- height: 0,
47413
- width: 0
47414
- }),
47415
- _React$useState2 = _slicedToArray(_React$useState, 2),
47416
- inputSize = _React$useState2[0],
47417
- setInputSize = _React$useState2[1];
47418
- var focusAnimation = React.useRef(new reactNative.Animated.Value(0)).current;
47419
- React.useEffect(function () {
47420
- reactNative.Animated.timing(focusAnimation, {
47421
- toValue: isFocused || !isEmptyValue ? 1 : 0,
47422
- duration: LABEL_ANIMATION_DURATION,
47423
- easing: reactNative.Easing.bezier(0.4, 0, 0.2, 1),
47424
- useNativeDriver: true
47425
- }).start();
47426
- }, [focusAnimation, isEmptyValue, isFocused]);
47427
- var onLayout = React.useCallback(function (event) {
47428
- var _event$nativeEvent$la = event.nativeEvent.layout,
47429
- height = _event$nativeEvent$la.height,
47430
- width = _event$nativeEvent$la.width;
47431
- setInputSize(function (prev) {
47432
- return _objectSpread2(_objectSpread2({}, prev), {}, {
47433
- height: height,
47434
- width: width
47435
- });
47436
- });
47437
- }, []);
47438
- React.useEffect(function () {
47439
- var removeFocusListener = on(emitter, normalizeEventName('editor-focus'), function () {
47440
- return setIsFocused(true);
47441
- });
47442
- var removeBlurListener = on(emitter, normalizeEventName('editor-blur'), function () {
47443
- return setIsFocused(false);
47444
- });
47445
- return function () {
47446
- removeFocusListener();
47447
- removeBlurListener();
47448
- };
47449
- }, []);
47450
47434
  var html = React.useMemo(function () {
47451
47435
  var initialValueString = JSON.stringify(value);
47452
47436
  return "\n <!DOCTYPE html>\n <html>\n <head>\n <meta charset=\"utf-8\">\n <meta name=\"viewport\" content=\"width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0\">\n <style>\n body {\n margin: 0;\n }\n </style>\n </head>\n <body>\n <div id=\"root\"></div>\n <script>\n window.__editorConfigs = {\n placeholder: \"".concat(placeholder, "\",\n initialValue: ").concat(initialValueString, ",\n isAndroid: ").concat(isAndroid ? 'true' : 'false', ",\n autoFocus: ").concat(autoFocus, ",\n style: {\n padding: '0 !important',\n fontSize: ").concat(theme.__hd__.richTextEditor.fontSizes.editor, ",\n color: '").concat(theme.__hd__.richTextEditor.colors.text, "'\n }\n };\n ").concat(heroEditorApp, "\n </script>\n </body>\n </html>\n ");
@@ -47480,7 +47464,7 @@ var RichTextEditor = function RichTextEditor(_ref) {
47480
47464
  }
47481
47465
  });
47482
47466
  }, []);
47483
- React.useImperativeHandle(forwardedRef, function () {
47467
+ React.useImperativeHandle(editorRef, function () {
47484
47468
  return {
47485
47469
  requestBlur: requestBlur,
47486
47470
  insertNodes: insertNodes,
@@ -47528,9 +47512,13 @@ var RichTextEditor = function RichTextEditor(_ref) {
47528
47512
  var messageData = message === null || message === void 0 ? void 0 : message.data;
47529
47513
  switch (messageType) {
47530
47514
  case '@hero-editor/webview/editor-focus':
47515
+ onFocus === null || onFocus === void 0 || onFocus();
47516
+ setIsFocused(true);
47531
47517
  emit(emitter, normalizeEventName('editor-focus'), undefined);
47532
47518
  break;
47533
47519
  case '@hero-editor/webview/editor-blur':
47520
+ onBlur === null || onBlur === void 0 || onBlur();
47521
+ setIsFocused(false);
47534
47522
  emit(emitter, normalizeEventName('editor-blur'), undefined);
47535
47523
  break;
47536
47524
  case '@hero-editor/webview/mention-search':
@@ -47548,7 +47536,107 @@ var RichTextEditor = function RichTextEditor(_ref) {
47548
47536
  handleEditorLayoutEvent(messageData);
47549
47537
  break;
47550
47538
  }
47539
+ }, [onFocus, onBlur]);
47540
+ return /*#__PURE__*/React__namespace.default.createElement(reactNative.TouchableWithoutFeedback, {
47541
+ onPress: function onPress(e) {
47542
+ return e.stopPropagation();
47543
+ }
47544
+ }, /*#__PURE__*/React__namespace.default.createElement(StyledWebView, {
47545
+ hideKeyboardAccessoryView: true,
47546
+ ref: webview,
47547
+ testID: testID,
47548
+ source: {
47549
+ html: html
47550
+ },
47551
+ onMessage: onMessage,
47552
+ scrollEnabled: false,
47553
+ originWhitelist: ['*'],
47554
+ keyboardDisplayRequiresUserAction: false,
47555
+ style: reactNative.StyleSheet.flatten([style, {
47556
+ height: webviewHeight
47557
+ }])
47558
+ }));
47559
+ };
47560
+
47561
+ var defaultValue = [{
47562
+ type: 'paragraph',
47563
+ children: [{
47564
+ text: ''
47565
+ }]
47566
+ }];
47567
+ var RichTextEditor = function RichTextEditor(_ref) {
47568
+ var _ref$autoFocus = _ref.autoFocus,
47569
+ autoFocus = _ref$autoFocus === void 0 ? true : _ref$autoFocus,
47570
+ name = _ref.name,
47571
+ _ref$placeholder = _ref.placeholder,
47572
+ placeholder = _ref$placeholder === void 0 ? '' : _ref$placeholder,
47573
+ onChange = _ref.onChange,
47574
+ onCursorChange = _ref.onCursorChange,
47575
+ _ref$error = _ref.error,
47576
+ error = _ref$error === void 0 ? '' : _ref$error,
47577
+ _ref$style = _ref.style,
47578
+ style = _ref$style === void 0 ? {} : _ref$style,
47579
+ label = _ref.label,
47580
+ helpText = _ref.helpText,
47581
+ required = _ref.required,
47582
+ testID = _ref.testID,
47583
+ onFocus = _ref.onFocus,
47584
+ onBlur = _ref.onBlur,
47585
+ forwardedRef = _ref.forwardedRef,
47586
+ _ref$value = _ref.value,
47587
+ value = _ref$value === void 0 ? defaultValue : _ref$value;
47588
+ var theme = useTheme();
47589
+ var _useState = React.useState(false),
47590
+ _useState2 = _slicedToArray(_useState, 2),
47591
+ isFocused = _useState2[0],
47592
+ setIsFocused = _useState2[1];
47593
+ var isEmptyValue = React.useMemo(function () {
47594
+ return libExports.isEmptyContent(value);
47595
+ }, [value]);
47596
+ var state = React.useMemo(function () {
47597
+ if (error) {
47598
+ return 'error';
47599
+ }
47600
+ if (isEmptyValue) {
47601
+ return 'filled';
47602
+ }
47603
+ return 'default';
47604
+ }, [isFocused, error, isEmptyValue]);
47605
+ var _React$useState = React__namespace.default.useState({
47606
+ height: 0,
47607
+ width: 0
47608
+ }),
47609
+ _React$useState2 = _slicedToArray(_React$useState, 2),
47610
+ inputSize = _React$useState2[0],
47611
+ setInputSize = _React$useState2[1];
47612
+ var focusAnimation = React.useRef(new reactNative.Animated.Value(0)).current;
47613
+ React.useEffect(function () {
47614
+ reactNative.Animated.timing(focusAnimation, {
47615
+ toValue: isFocused || !isEmptyValue ? 1 : 0,
47616
+ duration: LABEL_ANIMATION_DURATION,
47617
+ easing: reactNative.Easing.bezier(0.4, 0, 0.2, 1),
47618
+ useNativeDriver: true
47619
+ }).start();
47620
+ }, [focusAnimation, isEmptyValue, isFocused]);
47621
+ var onLayout = React.useCallback(function (event) {
47622
+ var _event$nativeEvent$la = event.nativeEvent.layout,
47623
+ height = _event$nativeEvent$la.height,
47624
+ width = _event$nativeEvent$la.width;
47625
+ setInputSize(function (prev) {
47626
+ return _objectSpread2(_objectSpread2({}, prev), {}, {
47627
+ height: height,
47628
+ width: width
47629
+ });
47630
+ });
47551
47631
  }, []);
47632
+ var handleEditorFocus = React.useCallback(function () {
47633
+ onFocus === null || onFocus === void 0 || onFocus();
47634
+ setIsFocused(true);
47635
+ }, [onFocus]);
47636
+ var handleEditorBlur = React.useCallback(function () {
47637
+ onBlur === null || onBlur === void 0 || onBlur();
47638
+ setIsFocused(false);
47639
+ }, [onBlur]);
47552
47640
  return /*#__PURE__*/React__namespace.default.createElement(StyledContainer$6, {
47553
47641
  testID: testID
47554
47642
  }, /*#__PURE__*/React__namespace.default.createElement(StyledLabelContainerInsideTextInput, {
@@ -47590,27 +47678,22 @@ var RichTextEditor = function RichTextEditor(_ref) {
47590
47678
  themeState: state,
47591
47679
  themeFocused: isFocused
47592
47680
  }), /*#__PURE__*/React__namespace.default.createElement(StyledTextInputAndLabelContainer, {
47593
- style: {
47594
- height: webviewHeight
47595
- },
47596
47681
  testID: "webViewWrapper"
47597
- }, /*#__PURE__*/React__namespace.default.createElement(reactNative.TouchableWithoutFeedback, {
47598
- onPress: function onPress(e) {
47599
- return e.stopPropagation();
47600
- }
47601
- }, /*#__PURE__*/React__namespace.default.createElement(StyledWebView, {
47602
- ref: webview,
47682
+ }, /*#__PURE__*/React__namespace.default.createElement(BaseRichTextEditor, {
47683
+ name: name,
47684
+ value: value,
47685
+ style: [style, {
47686
+ marginHorizontal: theme.__hd__.textInput.space.inputHorizontalMargin
47687
+ }],
47603
47688
  testID: "webview",
47604
- style: style,
47605
- originWhitelist: ['*'],
47606
- source: {
47607
- html: html
47608
- },
47609
- onMessage: onMessage,
47610
- scrollEnabled: false,
47611
- hideKeyboardAccessoryView: true,
47612
- keyboardDisplayRequiresUserAction: false
47613
- })))), /*#__PURE__*/React__namespace.default.createElement(StyledErrorAndHelpTextContainer, null, /*#__PURE__*/React__namespace.default.createElement(StyledErrorAndMaxLengthContainer, null, error ? /*#__PURE__*/React__namespace.default.createElement(StyledErrorContainer$2, null, /*#__PURE__*/React__namespace.default.createElement(Icon, {
47689
+ onChange: onChange,
47690
+ autoFocus: autoFocus,
47691
+ editorRef: forwardedRef,
47692
+ placeholder: placeholder,
47693
+ onBlur: handleEditorBlur,
47694
+ onFocus: handleEditorFocus,
47695
+ onCursorChange: onCursorChange
47696
+ }))), /*#__PURE__*/React__namespace.default.createElement(StyledErrorAndHelpTextContainer, null, /*#__PURE__*/React__namespace.default.createElement(StyledErrorAndMaxLengthContainer, null, error ? /*#__PURE__*/React__namespace.default.createElement(StyledErrorContainer$2, null, /*#__PURE__*/React__namespace.default.createElement(Icon, {
47614
47697
  testID: "input-error-icon",
47615
47698
  icon: "circle-info",
47616
47699
  size: "xsmall",
@@ -47627,8 +47710,12 @@ var RichTextEditorWithRef = /*#__PURE__*/React.forwardRef(function (props, ref)
47627
47710
  RichTextEditorWithRef.displayName = 'RichTextEditor';
47628
47711
 
47629
47712
  var index = Object.assign(RichTextEditorWithRef, {
47713
+ Toolbar: EditorToolbar,
47630
47714
  MentionList: MentionList,
47631
- Toolbar: EditorToolbar
47715
+ EditorEvents: EditorEvents,
47716
+ ToolbarEvents: ToolbarEvents,
47717
+ useRichTextEditorEvents: useRichTextEditorEvents,
47718
+ Base: BaseRichTextEditor
47632
47719
  });
47633
47720
 
47634
47721
  var LAST_BREAKPOINT = 100;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hero-design/rn",
3
- "version": "8.108.2",
3
+ "version": "8.109.0",
4
4
  "license": "MIT",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",