aboutsummaryrefslogtreecommitdiff
path: root/node_modules/@concordance/react/index.js
blob: 47ec117fafad7f9bef2b7c3fe545eb1d195aae27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
'use strict'

const pkg = require('./package.json')
const elementFactory = require('./lib/elementFactory')
const testJsonFactory = require('./lib/testJsonFactory')

// Must be unique across all registered plugins.
exports.name = pkg.name

// Expected API version to be passed to register().
exports.apiVersion = 1

// Expected minimal version of Concordance. Concordance will increment its API
// version for breaking changes, this is useful if you rely on features or
// patches that were introduced in a specific version of Concordance.
exports.minimalConcordanceVersion = '1.0.0'

// Plugin-specific version of its serialization output.
exports.serializerVersion = 1

exports.theme = {
  react: {
    functionType: '\u235F',
    openTag: {
      start: '<',
      end: '>',
      selfClose: '/',
      selfCloseVoid: ' /'
    },
    closeTag: {
      open: '</',
      close: '>'
    },
    tagName: {open: '', close: ''},
    attribute: {
      separator: '=',
      value: {
        openBracket: '{',
        closeBracket: '}',
        string: {
          line: {open: '"', close: '"', escapeQuote: '"'}
        }
      }
    },
    child: {
      openBracket: '{',
      closeBracket: '}',
      string: {
        line: {open: '', close: '', escapeQuote: ''},
        multiline: {start: '', end: '', escapeQuote: ''}
      }
    }
  }
}

const ELEMENT = Symbol.for('react.element')
const TEST_JSON = Symbol.for('react.test.json')

function register (api) {
  const reactTags = new Set()
  const element = elementFactory(api, reactTags)
  const testJson = testJsonFactory(api, element)

  api.addDescriptor(0x01, element.tag, element.deserialize)
  api.addDescriptor(0x02, testJson.tag, testJson.deserialize)

  reactTags.add(element.tag).add(testJson.tag)

  return value => {
    if (value.$$typeof === ELEMENT) return element.describe
    if (value.$$typeof === TEST_JSON) return testJson.describe
    return null
  }
}
exports.register = register