No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 

44 líneas
1.1 KiB

  1. /**
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. *
  7. * @format
  8. * @flow
  9. * @emails oncall+draft_js
  10. */
  11. 'use strict';
  12. import type ContentState from "./ContentState";
  13. const UnicodeBidiService = require("fbjs/lib/UnicodeBidiService");
  14. const Immutable = require("immutable");
  15. const nullthrows = require("fbjs/lib/nullthrows");
  16. const {
  17. OrderedMap
  18. } = Immutable;
  19. let bidiService;
  20. const EditorBidiService = {
  21. getDirectionMap: function (content: ContentState, prevBidiMap: ?OrderedMap<any, any>): OrderedMap<any, any> {
  22. if (!bidiService) {
  23. bidiService = new UnicodeBidiService();
  24. } else {
  25. bidiService.reset();
  26. }
  27. const blockMap = content.getBlockMap();
  28. const nextBidi = blockMap.valueSeq().map(block => nullthrows(bidiService).getDirection(block.getText()));
  29. const bidiMap = OrderedMap(blockMap.keySeq().zip(nextBidi));
  30. if (prevBidiMap != null && Immutable.is(prevBidiMap, bidiMap)) {
  31. return prevBidiMap;
  32. }
  33. return bidiMap;
  34. }
  35. };
  36. module.exports = EditorBidiService;