displayParams.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * <<
  3. * Davinci
  4. * ==
  5. * Copyright (C) 2016 - 2017 EDP
  6. * ==
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. * >>
  19. */
  20. import { IMigrationRecorder } from '.'
  21. import { ILayerParams } from 'app/containers/Display/components/types'
  22. import {
  23. migrationLabelRichTextContent,
  24. migrationLabelRichTextStyles
  25. } from 'app/containers/Display/components/Layer/RichText/util'
  26. import {
  27. slideSettings,
  28. SecondaryGraphTypes
  29. } from 'app/containers/Display/components/Setting/Form/constants'
  30. const slideSetting = slideSettings[SecondaryGraphTypes.Label]
  31. interface IDisplayParamsMigrationRecorder extends IMigrationRecorder {
  32. recorders: {
  33. beta9 (params: ILayerParams): ILayerParams
  34. }
  35. }
  36. const displayParamsMigrationRecorder: IDisplayParamsMigrationRecorder = {
  37. versions: ['beta9'],
  38. recorders: {
  39. beta9 (params) {
  40. if (!params.hasOwnProperty('richText')) {
  41. const { fontStyles, textStyles } = migrationLabelRichTextStyles(params)
  42. const contentText = Reflect.get(params, 'contentText')
  43. const defaultSettingParams = slideSetting.params
  44. .reduce((pre, cur) => {
  45. return pre.concat(cur.items)
  46. }, [])
  47. .map((obj) => obj.name)
  48. Object.keys(params).forEach((key) => {
  49. if (!defaultSettingParams.includes(key)) {
  50. Reflect.deleteProperty(params, key)
  51. }
  52. })
  53. params.richText = migrationLabelRichTextContent(
  54. contentText,
  55. fontStyles,
  56. textStyles
  57. )
  58. }
  59. return params
  60. }
  61. }
  62. }
  63. export default displayParamsMigrationRecorder