slackblock 0.4.0 → 1.0.0-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.
Files changed (139) hide show
  1. package/CHANGELOG.md +33 -26
  2. package/LICENSE +21 -21
  3. package/README.md +95 -85
  4. package/dist/block.cjs +341 -0
  5. package/dist/block.cjs.map +1 -0
  6. package/dist/block.d.mts +412 -0
  7. package/dist/block.d.ts +412 -0
  8. package/dist/block.mjs +268 -0
  9. package/dist/block.mjs.map +1 -0
  10. package/dist/index.cjs +1202 -0
  11. package/dist/index.cjs.map +1 -0
  12. package/dist/index.d.mts +6 -0
  13. package/dist/index.d.ts +6 -0
  14. package/dist/index.mjs +1170 -0
  15. package/dist/index.mjs.map +1 -0
  16. package/dist/types.d-DgQXbJte.d.mts +296 -0
  17. package/dist/types.d-DgQXbJte.d.ts +296 -0
  18. package/package.json +85 -135
  19. package/blocks.js +0 -12
  20. package/index.js +0 -7
  21. package/lib/components/block/button.js +0 -27
  22. package/lib/components/block/confirmation.js +0 -27
  23. package/lib/components/block/image.js +0 -27
  24. package/lib/components/block/text.js +0 -27
  25. package/lib/components/index.js +0 -42
  26. package/lib/components/input/date-picker.js +0 -27
  27. package/lib/components/input/option-group.js +0 -27
  28. package/lib/components/input/option.js +0 -27
  29. package/lib/components/input/overflow.js +0 -27
  30. package/lib/components/input/radio-group.js +0 -27
  31. package/lib/components/input/select.js +0 -34
  32. package/lib/components/input/text.js +0 -27
  33. package/lib/components/layout/actions.js +0 -27
  34. package/lib/components/layout/container.js +0 -27
  35. package/lib/components/layout/context.js +0 -27
  36. package/lib/components/layout/divider.js +0 -27
  37. package/lib/components/layout/file.js +0 -27
  38. package/lib/components/layout/image.js +0 -27
  39. package/lib/components/layout/input.js +0 -27
  40. package/lib/components/layout/section.js +0 -27
  41. package/lib/components/message.js +0 -27
  42. package/lib/index.js +0 -7
  43. package/lib/parser/index.js +0 -32
  44. package/lib/renderer/index.js +0 -71
  45. package/lib/transformers/block/button.js +0 -29
  46. package/lib/transformers/block/confirmation.js +0 -18
  47. package/lib/transformers/block/image.js +0 -10
  48. package/lib/transformers/block/text.js +0 -16
  49. package/lib/transformers/index.js +0 -54
  50. package/lib/transformers/input/date-picker.js +0 -30
  51. package/lib/transformers/input/option-group.js +0 -19
  52. package/lib/transformers/input/option.js +0 -19
  53. package/lib/transformers/input/overflow.js +0 -19
  54. package/lib/transformers/input/radio-group.js +0 -22
  55. package/lib/transformers/input/select.js +0 -84
  56. package/lib/transformers/input/text.js +0 -31
  57. package/lib/transformers/layout/actions.js +0 -18
  58. package/lib/transformers/layout/container.js +0 -11
  59. package/lib/transformers/layout/context.js +0 -18
  60. package/lib/transformers/layout/divider.js +0 -10
  61. package/lib/transformers/layout/file.js +0 -14
  62. package/lib/transformers/layout/image.js +0 -23
  63. package/lib/transformers/layout/input.js +0 -26
  64. package/lib/transformers/layout/section.js +0 -31
  65. package/lib/utils/get-type.js +0 -16
  66. package/lib/utils/type-helpers.js +0 -2
  67. package/src/components/block/button.tsx +0 -20
  68. package/src/components/block/confirmation.tsx +0 -19
  69. package/src/components/block/image.tsx +0 -8
  70. package/src/components/block/text.tsx +0 -10
  71. package/src/components/index.ts +0 -23
  72. package/src/components/input/date-picker.tsx +0 -11
  73. package/src/components/input/option-group.tsx +0 -9
  74. package/src/components/input/option.tsx +0 -9
  75. package/src/components/input/overflow.tsx +0 -12
  76. package/src/components/input/radio-group.tsx +0 -13
  77. package/src/components/input/select.tsx +0 -36
  78. package/src/components/input/text.tsx +0 -12
  79. package/src/components/layout/actions.tsx +0 -9
  80. package/src/components/layout/container.tsx +0 -9
  81. package/src/components/layout/context.tsx +0 -12
  82. package/src/components/layout/divider.tsx +0 -7
  83. package/src/components/layout/file.tsx +0 -8
  84. package/src/components/layout/image.tsx +0 -10
  85. package/src/components/layout/input.tsx +0 -12
  86. package/src/components/layout/section.tsx +0 -15
  87. package/src/components/message.tsx +0 -20
  88. package/src/constants/types.d.ts +0 -93
  89. package/src/index.ts +0 -3
  90. package/src/parser/index.ts +0 -32
  91. package/src/renderer/index.ts +0 -75
  92. package/src/transformers/block/button.tsx +0 -47
  93. package/src/transformers/block/confirmation.tsx +0 -26
  94. package/src/transformers/block/image.ts +0 -18
  95. package/src/transformers/block/text.ts +0 -34
  96. package/src/transformers/index.ts +0 -65
  97. package/src/transformers/input/date-picker.tsx +0 -43
  98. package/src/transformers/input/option-group.tsx +0 -26
  99. package/src/transformers/input/option.tsx +0 -27
  100. package/src/transformers/input/overflow.ts +0 -33
  101. package/src/transformers/input/radio-group.ts +0 -38
  102. package/src/transformers/input/select.tsx +0 -136
  103. package/src/transformers/input/text.tsx +0 -47
  104. package/src/transformers/layout/actions.ts +0 -29
  105. package/src/transformers/layout/container.ts +0 -16
  106. package/src/transformers/layout/context.ts +0 -35
  107. package/src/transformers/layout/divider.ts +0 -20
  108. package/src/transformers/layout/file.ts +0 -24
  109. package/src/transformers/layout/image.tsx +0 -34
  110. package/src/transformers/layout/input.tsx +0 -39
  111. package/src/transformers/layout/section.ts +0 -53
  112. package/src/tsconfig.json +0 -11
  113. package/src/utils/get-type.ts +0 -20
  114. package/src/utils/type-helpers.ts +0 -1
  115. package/test/index.test.tsx +0 -11
  116. package/test/parser/parser.test.tsx +0 -67
  117. package/test/renderer/renderer.test.tsx +0 -138
  118. package/test/transformers/block/button.test.tsx +0 -63
  119. package/test/transformers/block/confirmation.test.tsx +0 -37
  120. package/test/transformers/block/image.test.tsx +0 -20
  121. package/test/transformers/block/text.test.tsx +0 -32
  122. package/test/transformers/input/date-picker.test.tsx +0 -66
  123. package/test/transformers/input/option-group.test.tsx +0 -26
  124. package/test/transformers/input/option.test.tsx +0 -36
  125. package/test/transformers/input/overflow.test.tsx +0 -57
  126. package/test/transformers/input/radio-group.test.tsx +0 -81
  127. package/test/transformers/input/select.test.tsx +0 -249
  128. package/test/transformers/input/text.test.tsx +0 -42
  129. package/test/transformers/layout/actions.test.tsx +0 -33
  130. package/test/transformers/layout/container.test.tsx +0 -34
  131. package/test/transformers/layout/context.test.tsx +0 -43
  132. package/test/transformers/layout/divider.test.tsx +0 -20
  133. package/test/transformers/layout/file.test.tsx +0 -26
  134. package/test/transformers/layout/image.test.tsx +0 -43
  135. package/test/transformers/layout/input.test.tsx +0 -59
  136. package/test/transformers/layout/section.test.tsx +0 -89
  137. package/test/tsconfig.json +0 -9
  138. package/test/utils/get-type.test.tsx +0 -21
  139. package/tsconfig.json +0 -14
@@ -1,138 +0,0 @@
1
- import test from 'ava';
2
- import React from 'react';
3
- import proxyquire from 'proxyquire';
4
- import {stub} from 'sinon';
5
-
6
- import Message from '../../src/components/message';
7
- import Container from '../../src/components/layout/container';
8
- const parser = stub();
9
- const render = proxyquire('../../src/renderer', {
10
- '../parser': { default: parser }
11
- }).default
12
-
13
- test('it passes a list of children to the parser', t => {
14
- const content = 'block-content';
15
- render(<Message>{content}</Message>);
16
-
17
- t.true(parser.calledWith(content));
18
- });
19
-
20
- test('it throws an error if the passed component is not a <Message> component', t => {
21
- const fn = () => render(<div/>);
22
-
23
- t.throws(fn);
24
- });
25
-
26
- test('it throws an error if no children are passed', t => {
27
- // @ts-ignore - We want to explicitly check the lack of children
28
- const fn = () => render(<Message/>);
29
-
30
- t.throws(fn);
31
- });
32
-
33
- test('can render all props', t => {
34
- const content = 'content-of-block';
35
- const res = render(
36
- <Message
37
- text="text"
38
- iconEmoji=":icon_emoji:"
39
- iconUrl="iconUrl"
40
- markdown={false}
41
- parse="none"
42
- username="username"
43
- replyTo="replyTo"
44
- asUser
45
- replyBroadcast
46
- unfurlLinks
47
- unfurlMedia
48
- >
49
- {content}
50
- </Message>
51
- );
52
-
53
- t.deepEqual(res, {
54
- text: 'text',
55
- icon_emoji: ':icon_emoji:',
56
- icon_url: 'iconUrl',
57
- mrkdwn: false,
58
- parse: 'none',
59
- username: 'username',
60
- thread_ts: 'replyTo',
61
- as_user: true,
62
- reply_broadcast: true,
63
- unfurl_links: true,
64
- unfurl_media: true
65
- });
66
-
67
- t.true(parser.calledWith(content));
68
- });
69
-
70
- test('if no text prop is passed, uses a blank string', t => {
71
- const res = render(<Message>Hello</Message>);
72
-
73
- t.is(res.text, '');
74
- });
75
-
76
- test('if a color is passed, transforms the block elements to be within an attachment', t => {
77
- const content = 'abc';
78
- const returnContent = '<CONTENT>abc</CONTENT>'
79
- parser.withArgs(content).returns({
80
- blocks: [returnContent]
81
- });
82
- const res = render(
83
- <Message color="#FF0000">
84
- {content}
85
- </Message>
86
- );
87
-
88
- t.deepEqual(res, {
89
- text: '',
90
- attachments: [
91
- {
92
- color: '#FF0000',
93
- blocks: [
94
- returnContent
95
- ]
96
- }
97
- ]
98
- })
99
- });
100
-
101
- test('can render with a container block', t => {
102
- const content = 'content-of-block';
103
- const res = render(
104
- <Message
105
- text="text"
106
- iconEmoji=":icon_emoji:"
107
- iconUrl="iconUrl"
108
- markdown={false}
109
- parse="none"
110
- username="username"
111
- replyTo="replyTo"
112
- asUser
113
- replyBroadcast
114
- unfurlLinks
115
- unfurlMedia
116
- >
117
- <Container>
118
- {content}
119
- </Container>
120
- </Message>
121
- );
122
-
123
- t.deepEqual(res, {
124
- text: 'text',
125
- icon_emoji: ':icon_emoji:',
126
- icon_url: 'iconUrl',
127
- mrkdwn: false,
128
- parse: 'none',
129
- username: 'username',
130
- thread_ts: 'replyTo',
131
- as_user: true,
132
- reply_broadcast: true,
133
- unfurl_links: true,
134
- unfurl_media: true
135
- });
136
-
137
- t.true(parser.calledWith(content));
138
- })
@@ -1,63 +0,0 @@
1
- import test from 'ava';
2
- import React from 'react';
3
-
4
- import transformer from '../../../src/transformers/block/button';
5
- import confirmTransformer from '../../../src/transformers/block/confirmation';
6
- import Button from '../../../src/components/block/button';
7
- import Confirmation from '../../../src/components/block/confirmation';
8
- import Text from '../../../src/components/block/text';
9
-
10
- test('can transform a basic button', t => {
11
- const res = transformer(
12
- <Button actionId='actionId'>
13
- FooBar
14
- </Button>
15
- );
16
-
17
- t.deepEqual(res, {
18
- type: 'button',
19
- text: {
20
- type: 'plain_text',
21
- text: 'FooBar'
22
- },
23
- action_id: 'actionId'
24
- });
25
- });
26
-
27
- test('can transform a more advanced button', t => {
28
- const confirm = (
29
- <Confirmation
30
- title='ConfirmTitle'
31
- confirm='Confirm'
32
- deny='Deny'
33
- >
34
- <Text>FooBar</Text>
35
- </Confirmation>
36
- );
37
-
38
- const transformedConfirm = confirmTransformer(confirm);
39
- const res = transformer(
40
- <Button
41
- actionId='actionId'
42
- url='someURL'
43
- value='someValue'
44
- style='danger'
45
- confirm={confirm}
46
- >
47
- FooBar
48
- </Button>
49
- );
50
-
51
- t.deepEqual(res, {
52
- type: 'button',
53
- text: {
54
- type: 'plain_text',
55
- text: 'FooBar'
56
- },
57
- action_id: 'actionId',
58
- url: 'someURL',
59
- value: 'someValue',
60
- style: 'danger',
61
- confirm: transformedConfirm
62
- });
63
- });
@@ -1,37 +0,0 @@
1
- import test from 'ava';
2
- import React from 'react';
3
-
4
- import transformer from '../../../src/transformers/block/confirmation';
5
- import Confirmation from '../../../src/components/block/confirmation';
6
- import Text from '../../../src/components/block/text';
7
-
8
- test('transforms properly', t => {
9
- const res = transformer(
10
- <Confirmation
11
- title='SomeTitle'
12
- confirm='SomeConfirm'
13
- deny='SomeDeny'
14
- >
15
- <Text>FooBar</Text>
16
- </Confirmation>
17
- );
18
-
19
- t.deepEqual(res, {
20
- title: {
21
- type: 'plain_text',
22
- text: 'SomeTitle'
23
- },
24
- text: {
25
- type: 'mrkdwn',
26
- text: 'FooBar'
27
- },
28
- confirm: {
29
- type: 'plain_text',
30
- text: 'SomeConfirm'
31
- },
32
- deny: {
33
- type: 'plain_text',
34
- text: 'SomeDeny'
35
- }
36
- });
37
- });
@@ -1,20 +0,0 @@
1
- import React from 'react';
2
- import test from 'ava';
3
-
4
- import transformer from '../../../src/transformers/block/image';
5
- import Image from '../../../src/components/block/image';
6
-
7
- test('transforms an image block', t => {
8
- const res = transformer(
9
- <Image
10
- url="someUrl"
11
- alt="someAlt"
12
- />
13
- );
14
-
15
- t.deepEqual(res, {
16
- type: 'image',
17
- url: 'someUrl',
18
- alt: 'someAlt'
19
- });
20
- });
@@ -1,32 +0,0 @@
1
- import React from 'react';
2
- import test from 'ava';
3
- import Text from '../../../src/components/block/text';
4
- import transform from '../../../src/transformers/block/text';
5
-
6
- test('transforms text block', t => {
7
- const result = transform(<Text>Foo</Text>);
8
-
9
- t.deepEqual(result, {
10
- type: 'mrkdwn',
11
- text: 'Foo'
12
- });
13
- });
14
-
15
- test('transforms with optional parameters if supplied', t => {
16
- const result = transform(
17
- <Text
18
- plainText
19
- emoji
20
- verbatim
21
- >
22
- FooBar
23
- </Text>
24
- );
25
-
26
- t.deepEqual(result, {
27
- type: 'plain_text',
28
- text: 'FooBar',
29
- emoji: true,
30
- verbatim: true
31
- });
32
- });
@@ -1,66 +0,0 @@
1
- import React from 'react';
2
- import test from 'ava';
3
-
4
- import transformer from '../../../src/transformers/input/date-picker';
5
- import DatePicker from '../../../src/components/input/date-picker';
6
-
7
- import confirmTransformer from '../../../src/transformers/block/confirmation';
8
- import Confirmation from '../../../src/components/block/confirmation';
9
- import Text from '../../../src/components/block/text';
10
-
11
- test('transforms a simple DatePicker', t => {
12
- const res = transformer(
13
- <DatePicker
14
- actionId="actionId"
15
- />
16
- );
17
-
18
- t.deepEqual(res, {
19
- type: 'datepicker',
20
- action_id: 'actionId'
21
- });
22
- });
23
-
24
- test('transforms an advanced DatePicker', t => {
25
- const confirm = (
26
- <Confirmation
27
- title="someTitle"
28
- confirm="confirm"
29
- deny="deny"
30
- >
31
- <Text>Foo</Text>
32
- </Confirmation>
33
- );
34
- const transformedConfirm = confirmTransformer(confirm);
35
-
36
- const res = transformer(
37
- <DatePicker
38
- actionId="actionId"
39
- placeholder="placeholder"
40
- initialDate="2007-01-25"
41
- confirm={confirm}
42
- />
43
- );
44
-
45
- t.deepEqual(res, {
46
- type: 'datepicker',
47
- action_id: 'actionId',
48
- placeholder: {
49
- type: 'plain_text',
50
- text: 'placeholder'
51
- },
52
- initial_date: '2007-01-25',
53
- confirm: transformedConfirm
54
- });
55
- });
56
-
57
- test('rejects invalid dates', t => {
58
- const fn = () => transformer(
59
- <DatePicker
60
- actionId="aid"
61
- initialDate="invalid-date"
62
- />
63
- );
64
-
65
- t.throws(fn);
66
- });
@@ -1,26 +0,0 @@
1
- import React from 'react';
2
- import test from 'ava';
3
-
4
- import transformer from '../../../src/transformers/input/option-group';
5
- import optionTransformer from '../../../src/transformers/input/option';
6
- import Option from '../../../src/components/input/option';
7
- import OptionGroup from '../../../src/components/input/option-group';
8
-
9
- test('transforms an OptionGroup', t => {
10
- const option = <Option value="val">SomeOption</Option>;
11
- const transformedOption = optionTransformer(option);
12
-
13
- const res = transformer(
14
- <OptionGroup label="someLabel">
15
- {option}
16
- </OptionGroup>
17
- );
18
-
19
- t.deepEqual(res, {
20
- label: {
21
- type: 'plain_text',
22
- text: 'someLabel'
23
- },
24
- options: [transformedOption]
25
- });
26
- });
@@ -1,36 +0,0 @@
1
- import React from 'react';
2
- import test from 'ava';
3
-
4
- import transformer from '../../../src/transformers/input/option';
5
- import Option from '../../../src/components/input/option';
6
-
7
- test('transforms a basic option', t => {
8
- const res = transformer(<Option value="someValue">someText</Option>);
9
-
10
- t.deepEqual(res, {
11
- text: {
12
- type: 'plain_text',
13
- text: 'someText'
14
- },
15
- value: 'someValue'
16
- });
17
- });
18
-
19
- test('transforms an option with a url', t => {
20
- const res = transformer(
21
- <Option
22
- value="someValue"
23
- url="someUrl"
24
- >
25
- someText
26
- </Option>
27
- );
28
- t.deepEqual(res, {
29
- text: {
30
- type: 'plain_text',
31
- text: 'someText'
32
- },
33
- value: 'someValue',
34
- url: 'someUrl'
35
- });
36
- });
@@ -1,57 +0,0 @@
1
- import React from 'react';
2
- import test from 'ava';
3
-
4
- import transformer from '../../../src/transformers/input/overflow';
5
- import optionTransformer from '../../../src/transformers/input/option';
6
- import confirmTansformer from '../../../src/transformers/block/confirmation';
7
-
8
- import Overflow from '../../../src/components/input/overflow';
9
- import Option from '../../../src/components/input/option';
10
- import Confirmation from '../../../src/components/block/confirmation';
11
- import Text from '../../../src/components/block/text';
12
-
13
- test('transforms a basic Overflow block', t => {
14
- const option = <Option value="V">O</Option>;
15
- const options = [optionTransformer(option)];
16
-
17
- const res = transformer(
18
- <Overflow actionId="aid">
19
- {option}
20
- </Overflow>
21
- );
22
-
23
- t.deepEqual(res, {
24
- type: 'overflow',
25
- action_id: 'aid',
26
- options
27
- });
28
- });
29
-
30
- test('transforms an Overflow block with a confirmation', t => {
31
- const option = <Option value="V">O</Option>;
32
- const options = [optionTransformer(option)];
33
-
34
- const confirmation = (
35
- <Confirmation
36
- title="cTitle"
37
- confirm="cConfirm"
38
- deny="cDeny"
39
- >
40
- <Text>Foo</Text>
41
- </Confirmation>
42
- );
43
- const transformedConf = confirmTansformer(confirmation);
44
-
45
- const res = transformer(
46
- <Overflow actionId="aid" confirm={confirmation}>
47
- {option}
48
- </Overflow>
49
- );
50
-
51
- t.deepEqual(res, {
52
- type: 'overflow',
53
- action_id: 'aid',
54
- options,
55
- confirm: transformedConf
56
- });
57
- });
@@ -1,81 +0,0 @@
1
- import React from 'react';
2
- import test from 'ava';
3
-
4
- import transformer from '../../../src/transformers/input/radio-group';
5
- import optionTransformer from '../../../src/transformers/input/option';
6
- import confirmTansformer from '../../../src/transformers/block/confirmation';
7
-
8
- import RadioGroup from '../../../src/components/input/radio-group';
9
- import Option from '../../../src/components/input/option';
10
- import Confirmation from '../../../src/components/block/confirmation';
11
- import Text from '../../../src/components/block/text';
12
-
13
- test('transforms a basic RadioGroup block', t => {
14
- const option = <Option value="V">O</Option>;
15
- const option2 = <Option value="O">V</Option>;
16
- const options = [option, option2].map(optionTransformer);
17
-
18
- const res = transformer(
19
- <RadioGroup actionId="aid">
20
- {option}
21
- {option2}
22
- </RadioGroup>
23
- );
24
-
25
- t.deepEqual(res, {
26
- type: 'radio_buttons',
27
- action_id: 'aid',
28
- options
29
- });
30
- });
31
-
32
- test('can have an initial option', t => {
33
- const option = <Option value="V">O</Option>;
34
- const option2 = <Option value="O">V</Option>;
35
- const options = [option, option2].map(optionTransformer);
36
-
37
- const res = transformer(
38
- <RadioGroup actionId="aid" initialOption={option2}>
39
- {option}
40
- {option2}
41
- </RadioGroup>
42
- );
43
-
44
- t.deepEqual(res, {
45
- type: 'radio_buttons',
46
- action_id: 'aid',
47
- options,
48
- initial_option: optionTransformer(option2)
49
- });
50
- });
51
-
52
- test('can have a confirmation', t => {
53
- const option = <Option value="V">O</Option>;
54
- const option2 = <Option value="O">V</Option>;
55
- const options = [option, option2].map(optionTransformer);
56
-
57
- const confirmation = (
58
- <Confirmation
59
- title="cTitle"
60
- confirm="cConfirm"
61
- deny="cDeny"
62
- >
63
- <Text>Foo</Text>
64
- </Confirmation>
65
- );
66
- const transformedConf = confirmTansformer(confirmation);
67
-
68
- const res = transformer(
69
- <RadioGroup actionId="aid" confirm={confirmation}>
70
- {option}
71
- {option2}
72
- </RadioGroup>
73
- );
74
-
75
- t.deepEqual(res, {
76
- type: 'radio_buttons',
77
- action_id: 'aid',
78
- options,
79
- confirm: transformedConf
80
- });
81
- });