@storybook/addon-ondevice-notes 6.0.1-alpha.0 → 6.0.1-alpha.5

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.
@@ -1,14 +1,12 @@
1
1
  /**
2
2
  * mostly based on code from https://github.com/CharlesMangwa/react-native-simple-markdown
3
3
  */
4
- import { Component, ReactElement } from 'react';
4
+ import React from 'react';
5
5
  import { ImageStyle, TextStyle, ViewStyle } from 'react-native';
6
- import { ParserRules } from 'simple-markdown';
7
6
  export declare type Props = {
8
- children: string;
7
+ children?: string;
9
8
  errorHandler?: (errors: any[], children: string) => void;
10
- rules: ParserRules;
11
- styles: {
9
+ styles?: {
12
10
  view?: ViewStyle;
13
11
  text?: TextStyle;
14
12
  image?: ImageStyle;
@@ -17,13 +15,5 @@ export declare type Props = {
17
15
  export declare type DefaultProps = Props & {
18
16
  styles: Object;
19
17
  };
20
- declare class Markdown extends Component<Props> {
21
- static defaultProps: DefaultProps;
22
- shouldComponentUpdate: (nextProps: Props) => boolean;
23
- /** Post processes rules to strip out unwanted styling options
24
- * while keeping the default 'paragraph' and 'text' rules
25
- */
26
- _renderContent: (children: string) => ReactElement;
27
- render(): JSX.Element;
28
- }
29
- export default Markdown;
18
+ declare const _default: React.MemoExoticComponent<({ children, errorHandler, styles }: Props) => JSX.Element>;
19
+ export default _default;
@@ -1,26 +1,16 @@
1
1
  /**
2
2
  * mostly based on code from https://github.com/CharlesMangwa/react-native-simple-markdown
3
3
  */
4
- import React, { Component } from 'react';
4
+ import React from 'react';
5
5
  import { View } from 'react-native';
6
6
  import SimpleMarkdown from 'simple-markdown';
7
7
  // @ts-ignore
8
8
  import initialRules from './rules';
9
9
  import initialStyles from './styles';
10
- class Markdown extends Component {
11
- static defaultProps = {
12
- children: '',
13
- rules: {},
14
- styles: initialStyles,
15
- };
16
- shouldComponentUpdate = (nextProps) => this.props.children !== nextProps.children || this.props.styles !== nextProps.styles;
17
- // @TODO: Rewrite this part to prevent text from overriding other rules
18
- /** Post processes rules to strip out unwanted styling options
19
- * while keeping the default 'paragraph' and 'text' rules
20
- */
21
- _renderContent = (children) => {
10
+ const Markdown = ({ children = '', errorHandler, styles = initialStyles }) => {
11
+ const _renderContent = () => {
22
12
  try {
23
- const mergedStyles = { ...initialStyles, ...this.props.styles };
13
+ const mergedStyles = Object.assign(Object.assign({}, initialStyles), styles);
24
14
  const rules = initialRules(mergedStyles);
25
15
  // @TODO: Add another \n?
26
16
  const blockSource = `${children}\n\n`;
@@ -30,12 +20,10 @@ class Markdown extends Component {
30
20
  return SimpleMarkdown.outputFor(rules, 'react')(tree);
31
21
  }
32
22
  catch (errors) {
33
- this.props.errorHandler ? this.props.errorHandler(errors, children) : console.error(errors);
23
+ errorHandler ? errorHandler(errors, children) : console.error(errors);
34
24
  }
35
25
  return null;
36
26
  };
37
- render() {
38
- return <View style={[this.props.styles.view]}>{this._renderContent(this.props.children)}</View>;
39
- }
40
- }
41
- export default Markdown;
27
+ return React.createElement(View, { style: [styles.view] }, _renderContent());
28
+ };
29
+ export default React.memo(Markdown);
@@ -4,22 +4,14 @@
4
4
  import { createElement } from 'react';
5
5
  import { Image, Text, View, Linking, } from 'react-native';
6
6
  import SimpleMarkdown from 'simple-markdown';
7
- export default (styles) => ({
8
- ...SimpleMarkdown.defaultRules,
9
- autolink: {
10
- ...SimpleMarkdown.defaultRules.autolink,
11
- react: (node, output, state) => {
7
+ export default (styles) => (Object.assign(Object.assign({}, SimpleMarkdown.defaultRules), { autolink: Object.assign(Object.assign({}, SimpleMarkdown.defaultRules.autolink), { react: (node, output, state) => {
12
8
  state.withinText = true;
13
9
  return createElement(Text, {
14
10
  key: state.key,
15
11
  style: styles.link,
16
12
  onPress: () => null,
17
13
  }, output(node.content, state));
18
- },
19
- },
20
- blockQuote: {
21
- ...SimpleMarkdown.defaultRules.blockQuote,
22
- react: (node, output, state) => {
14
+ } }), blockQuote: Object.assign(Object.assign({}, SimpleMarkdown.defaultRules.blockQuote), { react: (node, output, state) => {
23
15
  state.withinText = true;
24
16
  const blockBar = createElement(View, {
25
17
  key: state.key,
@@ -33,51 +25,31 @@ export default (styles) => ({
33
25
  key: state.key,
34
26
  style: [styles.blockQuoteSection, styles.blockQuote],
35
27
  }, [blockBar, blockText]);
36
- },
37
- },
38
- br: {
39
- ...SimpleMarkdown.defaultRules.br,
40
- react: (node, output, state) => {
28
+ } }), br: Object.assign(Object.assign({}, SimpleMarkdown.defaultRules.br), { react: (node, output, state) => {
41
29
  return createElement(Text, {
42
30
  key: state.key,
43
31
  style: styles.br,
44
32
  }, '\n\n');
45
- },
46
- },
47
- codeBlock: {
48
- ...SimpleMarkdown.defaultRules.codeBlock,
49
- react: (node, output, state) => {
33
+ } }), codeBlock: Object.assign(Object.assign({}, SimpleMarkdown.defaultRules.codeBlock), { react: (node, output, state) => {
50
34
  state.withinText = true;
51
35
  return createElement(Text, {
52
36
  key: state.key,
53
37
  style: styles.codeBlock,
54
38
  }, null);
55
- },
56
- },
57
- del: {
58
- ...SimpleMarkdown.defaultRules.del,
59
- react: (node, output, state) => {
39
+ } }), del: Object.assign(Object.assign({}, SimpleMarkdown.defaultRules.del), { react: (node, output, state) => {
60
40
  state.withinText = true;
61
41
  return createElement(Text, {
62
42
  key: state.key,
63
43
  style: styles.del,
64
44
  }, output(node.content, state));
65
- },
66
- },
67
- em: {
68
- ...SimpleMarkdown.defaultRules.em,
69
- react: (node, output, state) => {
45
+ } }), em: Object.assign(Object.assign({}, SimpleMarkdown.defaultRules.em), { react: (node, output, state) => {
70
46
  state.withinText = true;
71
47
  return createElement(Text, {
72
48
  key: state.key,
73
49
  style: styles.em,
74
50
  }, output(node.content, state));
75
- },
76
- },
77
- heading: {
78
- ...SimpleMarkdown.defaultRules.heading,
79
- react: (node, output, parentState) => {
80
- const state = { ...parentState };
51
+ } }), heading: Object.assign(Object.assign({}, SimpleMarkdown.defaultRules.heading), { react: (node, output, parentState) => {
52
+ const state = Object.assign({}, parentState);
81
53
  state.withinText = true;
82
54
  const stylesToApply = [styles.heading, styles[`heading${node.level}`]];
83
55
  state.stylesToApply = stylesToApply;
@@ -85,35 +57,19 @@ export default (styles) => ({
85
57
  key: state.key,
86
58
  style: stylesToApply,
87
59
  }, output(node.content, state));
88
- },
89
- },
90
- hr: {
91
- ...SimpleMarkdown.defaultRules.hr,
92
- react: (node, output, state) => createElement(View, { key: state.key, style: styles.hr }),
93
- },
94
- image: {
95
- ...SimpleMarkdown.defaultRules.image,
96
- react: (node, output, state) => createElement(Image, {
60
+ } }), hr: Object.assign(Object.assign({}, SimpleMarkdown.defaultRules.hr), { react: (node, output, state) => createElement(View, { key: state.key, style: styles.hr }) }), image: Object.assign(Object.assign({}, SimpleMarkdown.defaultRules.image), { react: (node, output, state) => createElement(Image, {
97
61
  key: state.key,
98
62
  resizeMode: 'contain',
99
63
  source: { uri: node.target },
100
64
  style: (node.target.match(/youtu|vimeo/) ? styles.video : styles.image),
101
65
  //styles.resizeMode ? styles.resizeMode :
102
- }),
103
- },
104
- inlineCode: {
105
- ...SimpleMarkdown.defaultRules.inlineCode,
106
- react: (node, output, state) => {
66
+ }) }), inlineCode: Object.assign(Object.assign({}, SimpleMarkdown.defaultRules.inlineCode), { react: (node, output, state) => {
107
67
  state.withinText = true;
108
68
  return createElement(Text, {
109
69
  key: state.key,
110
70
  style: styles.inlineCode,
111
71
  }, node.content);
112
- },
113
- },
114
- link: {
115
- ...SimpleMarkdown.defaultRules.link,
116
- react: (node, output, state) => {
72
+ } }), link: Object.assign(Object.assign({}, SimpleMarkdown.defaultRules.link), { react: (node, output, state) => {
117
73
  state.withinText = true;
118
74
  const openUrl = (url) => {
119
75
  Linking.openURL(url).catch((error) => console.warn('An error occurred: ', error));
@@ -123,11 +79,7 @@ export default (styles) => ({
123
79
  key: state.key,
124
80
  onPress: () => openUrl(node.target),
125
81
  }, output(node.content, state));
126
- },
127
- },
128
- list: {
129
- ...SimpleMarkdown.defaultRules.list,
130
- react: (node, output, state) => {
82
+ } }), list: Object.assign(Object.assign({}, SimpleMarkdown.defaultRules.list), { react: (node, output, state) => {
131
83
  const items = node.items.map((item, i) => {
132
84
  let bullet;
133
85
  if (node.ordered) {
@@ -143,35 +95,19 @@ export default (styles) => ({
143
95
  }, [bullet, listItemText]);
144
96
  });
145
97
  return createElement(View, { key: state.key, style: styles.list }, items);
146
- },
147
- },
148
- newline: {
149
- ...SimpleMarkdown.defaultRules.newline,
150
- react: (node, output, state) => createElement(Text, {
98
+ } }), newline: Object.assign(Object.assign({}, SimpleMarkdown.defaultRules.newline), { react: (node, output, state) => createElement(Text, {
151
99
  key: state.key,
152
100
  style: styles.newline,
153
- }, '\n'),
154
- },
155
- paragraph: {
156
- ...SimpleMarkdown.defaultRules.paragraph,
157
- react: (node, output, state) => createElement(View, {
101
+ }, '\n') }), paragraph: Object.assign(Object.assign({}, SimpleMarkdown.defaultRules.paragraph), { react: (node, output, state) => createElement(View, {
158
102
  key: state.key,
159
103
  style: styles.paragraph,
160
- }, output(node.content, state)),
161
- },
162
- strong: {
163
- ...SimpleMarkdown.defaultRules.strong,
164
- react: (node, output, state) => {
104
+ }, output(node.content, state)) }), strong: Object.assign(Object.assign({}, SimpleMarkdown.defaultRules.strong), { react: (node, output, state) => {
165
105
  state.withinText = true;
166
106
  return createElement(Text, {
167
107
  key: state.key,
168
108
  style: styles.strong,
169
109
  }, output(node.content, state));
170
- },
171
- },
172
- table: {
173
- ...SimpleMarkdown.defaultRules.table,
174
- react: (node, output, state) => {
110
+ } }), table: Object.assign(Object.assign({}, SimpleMarkdown.defaultRules.table), { react: (node, output, state) => {
175
111
  const headers = node.header.map((content, i) => createElement(Text, {
176
112
  style: styles.tableHeaderCell,
177
113
  key: i,
@@ -187,12 +123,8 @@ export default (styles) => ({
187
123
  return createElement(View, { key: r, style: rowStyles }, cells);
188
124
  });
189
125
  return createElement(View, { key: state.key, style: styles.table }, [header, rows]);
190
- },
191
- },
192
- text: {
193
- ...SimpleMarkdown.defaultRules.text,
194
- react: (node, output, parentState) => {
195
- const state = { ...parentState };
126
+ } }), text: Object.assign(Object.assign({}, SimpleMarkdown.defaultRules.text), { react: (node, output, parentState) => {
127
+ const state = Object.assign({}, parentState);
196
128
  // Breaking words up in order to allow for text reflowing in flexbox
197
129
  // let words = node.content.split(' ');
198
130
  // words = words.map((word: string, i: number) => {
@@ -204,21 +136,13 @@ export default (styles) => ({
204
136
  key: state.key,
205
137
  style: textStyles,
206
138
  }, node.content);
207
- },
208
- },
209
- u: {
210
- ...SimpleMarkdown.defaultRules.u,
211
- react: (node, output, state) => {
139
+ } }), u: Object.assign(Object.assign({}, SimpleMarkdown.defaultRules.u), { react: (node, output, state) => {
212
140
  state.withinText = true;
213
141
  return createElement(Text, {
214
142
  key: state.key,
215
143
  style: styles.u,
216
144
  }, output(node.content, state));
217
- },
218
- },
219
- url: {
220
- ...SimpleMarkdown.defaultRules.url,
221
- react: (node, output, state) => {
145
+ } }), url: Object.assign(Object.assign({}, SimpleMarkdown.defaultRules.url), { react: (node, output, state) => {
222
146
  state.withinText = true;
223
147
  const openURL = (url) => {
224
148
  Linking.openURL(url).catch((error) => console.warn('An error occurred: ', error));
@@ -228,6 +152,4 @@ export default (styles) => ({
228
152
  style: styles.url,
229
153
  onPress: () => openURL(node.target),
230
154
  }, output(node.content, state));
231
- },
232
- },
233
- });
155
+ } }) }));
@@ -21,9 +21,8 @@ export const Notes = ({ active, api }) => {
21
21
  }
22
22
  const text = story.parameters[PARAM_KEY];
23
23
  const textAfterFormatted = text ? text.trim() : '';
24
- return (<View style={styles.container}>
25
- <Markdown>{textAfterFormatted}</Markdown>
26
- </View>);
24
+ return (React.createElement(View, { style: styles.container },
25
+ React.createElement(Markdown, null, textAfterFormatted)));
27
26
  };
28
27
  const styles = StyleSheet.create({
29
28
  container: { padding: 10, flex: 1 },
package/dist/register.js CHANGED
@@ -6,7 +6,7 @@ addons.register('storybook/notes', (api) => {
6
6
  const channel = addons.getChannel();
7
7
  addons.addPanel('storybook/notes/panel', {
8
8
  title: 'Notes',
9
- render: ({ active, key }) => <Notes key={key} channel={channel} api={api} active={active}/>,
9
+ render: ({ active, key }) => React.createElement(Notes, { key: key, channel: channel, api: api, active: active }),
10
10
  paramKey: PARAM_KEY,
11
11
  });
12
12
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/addon-ondevice-notes",
3
- "version": "6.0.1-alpha.0",
3
+ "version": "6.0.1-alpha.5",
4
4
  "description": "Write notes for your react-native Storybook stories.",
5
5
  "keywords": [
6
6
  "addon",
@@ -45,5 +45,5 @@
45
45
  "publishConfig": {
46
46
  "access": "public"
47
47
  },
48
- "gitHead": "d1902e4b183a703f0a1bc24879acb0693ab616cf"
48
+ "gitHead": "6f8419cefb00be5cf88132a626b768ec8a332515"
49
49
  }