@podlite/to-jsx 0.0.8 → 0.0.12

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.
package/lib/index.js CHANGED
@@ -1,14 +1,4 @@
1
- var __assign = (this && this.__assign) || function () {
2
- __assign = Object.assign || function(t) {
3
- for (var s, i = 1, n = arguments.length; i < n; i++) {
4
- s = arguments[i];
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
- t[p] = s[p];
7
- }
8
- return t;
9
- };
10
- return __assign.apply(this, arguments);
11
- };
1
+ "use strict";
12
2
  var __rest = (this && this.__rest) || function (s, e) {
13
3
  var t = {};
14
4
  for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
@@ -20,66 +10,41 @@ var __rest = (this && this.__rest) || function (s, e) {
20
10
  }
21
11
  return t;
22
12
  };
23
- var __read = (this && this.__read) || function (o, n) {
24
- var m = typeof Symbol === "function" && o[Symbol.iterator];
25
- if (!m) return o;
26
- var i = m.call(o), r, ar = [], e;
27
- try {
28
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
29
- }
30
- catch (error) { e = { error: error }; }
31
- finally {
32
- try {
33
- if (r && !r.done && (m = i["return"])) m.call(i);
34
- }
35
- finally { if (e) throw e.error; }
36
- }
37
- return ar;
38
- };
39
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
40
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
41
- if (ar || !(i in from)) {
42
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
43
- ar[i] = from[i];
44
- }
45
- }
46
- return to.concat(ar || Array.prototype.slice.call(from));
47
- };
48
- import React from 'react';
49
- import toAny from 'pod6/built/exportAny';
50
- import { subUse, emptyContent, content as nodeContent, setFn } from 'pod6/built/helpers/handlers';
51
- import clean_plugin from 'pod6/built/plugin-clean-location';
52
- import makeAttrs from 'pod6/built/helpers/config';
53
- import { isNamedBlock, isSemanticBlock } from 'pod6/built/helpers/makeTransformer';
54
- import { parse } from 'pod6';
55
- import Writer from 'pod6/built/writer';
56
- import { podlite as podlite_core } from 'podlite';
57
- import Diagram from '@podlite/diagram';
58
- import { getNodeId } from '@podlite/schema';
59
- var helperMakeReact = function (_a) {
60
- var wrapElement = _a.wrapElement;
61
- var i_key_i = 0;
62
- var mapByType = {};
63
- var getIdForNode = function (_a) {
64
- var _b = _a.type, type = _b === void 0 ? "notype" : _b, _c = _a.name, name = _c === void 0 ? "noname" : _c;
65
- var type_idx = "".concat(type, "_").concat(name);
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.Podlite = void 0;
15
+ const React = require("react");
16
+ const react_1 = require("react");
17
+ const exportAny_1 = require("pod6/built/exportAny");
18
+ const handlers_1 = require("pod6/built/helpers/handlers");
19
+ const plugin_clean_location_1 = require("pod6/built/plugin-clean-location");
20
+ const config_1 = require("pod6/built/helpers/config");
21
+ const makeTransformer_1 = require("pod6/built/helpers/makeTransformer");
22
+ const pod6_1 = require("pod6");
23
+ const writer_1 = require("pod6/built/writer");
24
+ const podlite_1 = require("podlite");
25
+ const diagram_1 = require("@podlite/diagram");
26
+ const schema_1 = require("@podlite/schema");
27
+ const helperMakeReact = ({ wrapElement }) => {
28
+ let i_key_i = 0;
29
+ let mapByType = {};
30
+ const getIdForNode = ({ type = "notype", name = "noname" }) => {
31
+ const type_idx = `${type}_${name}`;
66
32
  if (!mapByType[type_idx]) {
67
33
  mapByType[type_idx] = 0;
68
34
  }
69
35
  ++mapByType[type_idx];
70
- return "".concat(type_idx, "_").concat(mapByType[type_idx]);
36
+ return `${type_idx}_${mapByType[type_idx]}`;
71
37
  };
72
- return function (src, node, children, extraProps) {
73
- if (extraProps === void 0) { extraProps = {}; }
38
+ return function (src, node, children, extraProps = {}) {
74
39
  // for string return it
75
40
  if (typeof node == 'string') {
76
41
  return node;
77
42
  }
78
- var attr = __rest(node, []);
79
- var key = 'type' in node && node.type ? getIdForNode(node) : ++i_key_i;
80
- var result = typeof src === 'function'
81
- ? src(__assign(__assign({}, attr), { key: key, children: children }), children)
82
- : React.createElement(src, __assign(__assign({}, extraProps), { key: key }), children);
43
+ const attr = __rest(node, []);
44
+ const key = 'type' in node && node.type ? getIdForNode(node) : ++i_key_i;
45
+ const result = typeof src === 'function'
46
+ ? src(Object.assign(Object.assign({}, attr), { key, children }), children)
47
+ : (0, react_1.createElement)(src, Object.assign(Object.assign({}, extraProps), { key }), children);
83
48
  // // create react element and pass key
84
49
  // if (!isValidElementType(src)) {
85
50
  // throw new Error(`Bad React element for ${ruleName} rule `)
@@ -90,167 +55,144 @@ var helperMakeReact = function (_a) {
90
55
  return result;
91
56
  };
92
57
  };
93
- var Podlite = function (_a) {
94
- var children = _a.children, options = __rest(_a, ["children"]);
95
- var result = podlite(children, options);
58
+ const Podlite = (_a) => {
59
+ var { children } = _a, options = __rest(_a, ["children"]);
60
+ const result = podlite(children, options);
96
61
  return result;
97
62
  };
98
- var mapToReact = function (makeComponent) {
99
- var mkComponent = function (src) { return function (writer, processor) { return function (node, ctx, interator) {
63
+ exports.Podlite = Podlite;
64
+ const mapToReact = (makeComponent) => {
65
+ const mkComponent = (src) => (writer, processor) => (node, ctx, interator) => {
100
66
  // check if node.content defined
101
- return makeComponent(src, node, 'content' in node ? interator(node.content, __assign({}, ctx)) : []);
102
- }; }; };
67
+ return makeComponent(src, node, 'content' in node ? interator(node.content, Object.assign({}, ctx)) : []);
68
+ };
103
69
  // Handle nested block and :nested block attribute
104
- var handleNested = function (defaultHandler, implicitLevel) {
105
- return function (writer, processor) {
106
- var defaultHandlerInited = defaultHandler(writer, processor);
107
- return function (node, ctx, interator) {
108
- var nesting = makeAttrs(node, ctx).getFirstValue('nested') || implicitLevel;
109
- var children = defaultHandlerInited(node, ctx, interator);
70
+ const handleNested = (defaultHandler, implicitLevel) => {
71
+ return (writer, processor) => {
72
+ const defaultHandlerInited = defaultHandler(writer, processor);
73
+ return (node, ctx, interator) => {
74
+ const nesting = (0, config_1.default)(node, ctx).getFirstValue('nested') || implicitLevel;
75
+ const children = defaultHandlerInited(node, ctx, interator);
110
76
  // if no nesting needs - simply return children
111
77
  if (!nesting) {
112
78
  return children;
113
79
  }
114
- var arr = __spreadArray([], __read(Array(nesting).keys()), false);
115
- return arr.reduce(function (acc) { return makeComponent('blockquote', node, acc); }, children);
80
+ const arr = [...Array(nesting).keys()];
81
+ return arr.reduce((acc) => makeComponent('blockquote', node, acc), children);
116
82
  };
117
83
  };
118
84
  };
119
85
  return {
120
86
  'pod': mkComponent('div'),
121
- 'root': nodeContent,
122
- 'data': emptyContent(),
123
- ':ambient': emptyContent(),
124
- ':code': mkComponent(function (_a) {
125
- var children = _a.children, key = _a.key;
126
- return React.createElement("code", { key: key },
127
- React.createElement("pre", null, children));
128
- }),
129
- 'code': mkComponent(function (_a) {
130
- var children = _a.children, key = _a.key;
131
- return React.createElement("code", { key: key },
132
- React.createElement("pre", null, children));
133
- }),
134
- 'Image': subUse({
87
+ 'root': handlers_1.content,
88
+ 'data': (0, handlers_1.emptyContent)(),
89
+ ':ambient': (0, handlers_1.emptyContent)(),
90
+ ':code': mkComponent(({ children, key }) => React.createElement("code", { key: key },
91
+ React.createElement("pre", null, children))),
92
+ 'code': mkComponent(({ children, key }) => React.createElement("code", { key: key },
93
+ React.createElement("pre", null, children))),
94
+ 'Image': (0, handlers_1.subUse)({
135
95
  // inside head don't wrap into <p>
136
- ':image': setFn(function (node, ctx) {
137
- var linkTo = ctx.link;
138
- return mkComponent(function (_a) {
139
- var children = _a.children, key = _a.key;
140
- var Img = React.createElement("img", { key: key, src: node.src, alt: node.alt });
96
+ ':image': (0, handlers_1.setFn)((node, ctx) => {
97
+ const linkTo = ctx.link;
98
+ return mkComponent(({ children, key }) => {
99
+ const Img = node.src.match(/(mp4|mov)$/)
100
+ ? React.createElement("video", { controls: true, key: key },
101
+ " ",
102
+ React.createElement("source", { src: node.src, type: "video/mp4" }),
103
+ " ")
104
+ : React.createElement("img", { key: key, src: node.src, alt: node.alt });
141
105
  return linkTo ? React.createElement("a", { key: key, href: linkTo }, Img) : Img;
142
106
  });
143
107
  }),
144
- 'caption': mkComponent(function (_a) {
145
- var children = _a.children, key = _a.key;
146
- return React.createElement("div", { className: "caption", key: key }, children);
147
- })
148
- }, setFn(function (node, ctx) {
149
- var level = node.level;
150
- var id = getNodeId(node, ctx);
151
- var conf = makeAttrs(node, ctx);
108
+ 'caption': mkComponent(({ children, key }) => React.createElement("div", { className: "caption", key: key }, children))
109
+ }, (0, handlers_1.setFn)((node, ctx) => {
110
+ const { level } = node;
111
+ const id = (0, schema_1.getNodeId)(node, ctx);
112
+ const conf = (0, config_1.default)(node, ctx);
152
113
  if (conf.exists('link')) {
153
114
  ctx.link = conf.getFirstValue('link');
154
115
  }
155
- return mkComponent(function (_a) {
156
- var children = _a.children, key = _a.key;
157
- return React.createElement("div", { className: "image_block", key: key, id: id }, children);
158
- });
116
+ return mkComponent(({ children, key }) => React.createElement("div", { className: "image_block", key: key, id: id }, children));
159
117
  })),
160
- 'image': nodeContent,
161
- ':image': setFn(function (node, ctx) {
162
- return mkComponent(function (_a) {
163
- var children = _a.children, key = _a.key;
164
- return React.createElement("img", { key: key, src: node.src, alt: node.alt });
165
- });
118
+ 'image': handlers_1.content,
119
+ ':image': (0, handlers_1.setFn)((node, ctx) => {
120
+ return mkComponent(({ children, key }) => React.createElement("img", { key: key, src: node.src, alt: node.alt }));
166
121
  }),
167
- 'Diagram': function () { return function (node, ctx, interator) {
168
- var conf = makeAttrs(node, ctx);
169
- var caption = conf.exists("caption")
122
+ 'Diagram': () => (node, ctx, interator) => {
123
+ const conf = (0, config_1.default)(node, ctx);
124
+ const caption = conf.exists("caption")
170
125
  ? conf.getFirstValue("caption")
171
126
  : null;
172
- var id = getNodeId(node, ctx);
173
- return makeComponent(function (_a) {
174
- var children = _a.children, key = _a.key;
175
- return React.createElement(Diagram, { id: id, isError: node.custom, caption: caption, chart: node.content[0].value });
176
- }, node, interator(node.content, __assign({}, ctx)));
177
- }; },
178
- ':text': function (writer, processor) { return function (node, ctx, interator) {
127
+ const id = (0, schema_1.getNodeId)(node, ctx);
128
+ return makeComponent(({ children, key }) => {
129
+ return React.createElement(diagram_1.default, { id: id, isError: node.custom, caption: caption, chart: node.content[0].value });
130
+ }, node, interator(node.content, Object.assign({}, ctx)));
131
+ },
132
+ ':text': (writer, processor) => (node, ctx, interator) => {
179
133
  return node.value;
180
- }; },
181
- ':verbatim': function (writer, processor) { return function (node, ctx, interator) {
134
+ },
135
+ ':verbatim': (writer, processor) => (node, ctx, interator) => {
182
136
  return node.value;
183
- }; },
184
- 'head:block': subUse({
137
+ },
138
+ 'head:block': (0, handlers_1.subUse)({
185
139
  // inside head don't wrap into <p>
186
- ':para': nodeContent,
187
- }, setFn(function (node, ctx) {
188
- var level = node.level;
189
- var id = getNodeId(node, ctx);
190
- return mkComponent(function (_a) {
191
- var level = _a.level, children = _a.children, key = _a.key;
192
- return React.createElement("h".concat(level), { key: key, id: id }, children);
193
- });
140
+ ':para': handlers_1.content,
141
+ }, (0, handlers_1.setFn)((node, ctx) => {
142
+ const { level } = node;
143
+ const id = (0, schema_1.getNodeId)(node, ctx);
144
+ return mkComponent(({ level, children, key }) => (0, react_1.createElement)(`h${level}`, { key, id }, children));
194
145
  })),
195
- ':blankline': emptyContent(),
146
+ ':blankline': (0, handlers_1.emptyContent)(),
196
147
  ':para': mkComponent('p'),
197
148
  'para': mkComponent('div'),
198
- 'comment:block': emptyContent(),
199
- 'defn': subUse([
149
+ 'comment:block': (0, handlers_1.emptyContent)(),
150
+ 'defn': (0, handlers_1.subUse)([
200
151
  // to avoid overlap para blocks handlers
201
152
  // define general :para at first
202
153
  { ':para': mkComponent('dd') },
203
154
  { 'term:para': mkComponent('dt') },
204
- ], nodeContent),
205
- "nested": handleNested(nodeContent, 1),
206
- 'output': mkComponent(function (_a) {
207
- var children = _a.children, key = _a.key;
208
- return React.createElement("pre", { key: key },
209
- React.createElement("samp", null, children));
210
- }),
211
- 'input': mkComponent(function (_a) {
212
- var children = _a.children, key = _a.key;
213
- return React.createElement("pre", { key: key },
214
- React.createElement("kbd", null, children));
215
- }),
155
+ ], handlers_1.content),
156
+ "nested": handleNested(handlers_1.content, 1),
157
+ 'output': mkComponent(({ children, key }) => React.createElement("pre", { key: key },
158
+ React.createElement("samp", null, children))),
159
+ 'input': mkComponent(({ children, key }) => React.createElement("pre", { key: key },
160
+ React.createElement("kbd", null, children))),
216
161
  // Directives
217
- ':config': setFn(function (node, ctx) {
162
+ ':config': (0, handlers_1.setFn)((node, ctx) => {
218
163
  // setup context
219
164
  if (!ctx.hasOwnProperty('config'))
220
165
  ctx.config = {};
221
166
  //collect configs in context
222
167
  ctx.config[node.name] = node.config;
223
- return emptyContent();
168
+ return (0, handlers_1.emptyContent)();
224
169
  }),
225
- ':alias': setFn(function (node, ctx) {
170
+ ':alias': (0, handlers_1.setFn)((node, ctx) => {
226
171
  // set alias
227
172
  if (!ctx.hasOwnProperty('alias'))
228
173
  ctx.alias = {};
229
174
  //collect configs in context
230
175
  ctx.alias[node.name] = node.replacement;
231
- return emptyContent();
176
+ return (0, handlers_1.emptyContent)();
232
177
  }),
233
178
  // Formatting codes
234
- 'A<>': function (writer, processor) { return function (node, ctx, interator) {
235
- var term = node.content;
179
+ 'A<>': (writer, processor) => (node, ctx, interator) => {
180
+ let term = node.content;
236
181
  if (typeof term !== 'string' && 'value' in term) {
237
182
  term = term.value;
238
183
  }
239
184
  //get replacement text
240
185
  if (!(ctx.alias && ctx.alias.hasOwnProperty(term))) {
241
- return makeComponent(function (_a) {
242
- var children = _a.children, key = _a.key;
243
- return React.createElement("code", { key: key },
244
- "A<",
245
- children,
246
- ">");
247
- }, node, interator(node.content, ctx));
186
+ return makeComponent(({ children, key }) => React.createElement("code", { key: key },
187
+ "A<",
188
+ children,
189
+ ">"), node, interator(node.content, ctx));
248
190
  }
249
191
  else {
250
- var src = ctx.alias[term].join('\n');
251
- var tree_1 = processor(src);
192
+ const src = ctx.alias[term].join('\n');
193
+ const tree_1 = processor(src);
252
194
  // now clean locations
253
- var tree = clean_plugin()(tree_1);
195
+ const tree = (0, plugin_clean_location_1.default)()(tree_1);
254
196
  if (tree[0].type === 'para') {
255
197
  return interator(tree[0].content, ctx);
256
198
  }
@@ -258,15 +200,15 @@ var mapToReact = function (makeComponent) {
258
200
  return interator(tree, ctx);
259
201
  }
260
202
  }
261
- }; },
203
+ },
262
204
  'B<>': mkComponent('strong'),
263
205
  'C<>': mkComponent('code'),
264
- 'E<>': function (writer, processor) { return function (node, ctx, interator) {
206
+ 'E<>': (writer, processor) => (node, ctx, interator) => {
265
207
  if ('content' in node && Array.isArray(node.content))
266
- return node.content.filter(function (e) { return e && e.type == 'number'; }).map(function (element) {
208
+ return node.content.filter(e => e && e.type == 'number').map(element => {
267
209
  return String.fromCharCode(element.value);
268
210
  }).join('');
269
- }; },
211
+ },
270
212
  'I<>': mkComponent('i'),
271
213
  'K<>': mkComponent('kbd'),
272
214
  /**
@@ -281,33 +223,30 @@ var mapToReact = function (makeComponent) {
281
223
  border-top-color: #eee;
282
224
  }
283
225
  */
284
- 'N<>': function (writer, processor) {
285
- writer.addListener('end', function () {
226
+ 'N<>': (writer, processor) => {
227
+ writer.addListener('end', () => {
286
228
  if (!writer.hasOwnProperty('FOOTNOTES')) {
287
229
  return;
288
230
  }
289
- var footnotes = writer.FOOTNOTES;
231
+ const footnotes = writer.FOOTNOTES;
290
232
  if (footnotes.length < 1) {
291
233
  return;
292
234
  } // if empty footnotes
293
235
  if (!writer.hasOwnProperty('postInterator')) {
294
236
  writer.postInterator = [];
295
237
  }
296
- var FootNotes = makeComponent(function (_a) {
297
- var children = _a.children, key = _a.key;
298
- return React.createElement("div", { key: "".concat(key, "_FOOTNOTES"), className: "footnotes" }, footnotes.map(function (footnote, id) {
299
- return React.createElement("p", { key: id },
300
- React.createElement("sup", { id: footnote.fnId, className: "footnote" },
301
- React.createElement("a", { href: "#".concat(footnote.fnRefId) },
302
- "[",
303
- footnote.gid,
304
- "]")),
305
- footnote.make());
306
- }));
307
- }, {});
238
+ const FootNotes = makeComponent(({ children, key }) => React.createElement("div", { key: `${key}_FOOTNOTES`, className: "footnotes" }, footnotes.map((footnote, id) => {
239
+ return React.createElement("p", { key: id },
240
+ React.createElement("sup", { id: footnote.fnId, className: "footnote" },
241
+ React.createElement("a", { href: `#${footnote.fnRefId}` },
242
+ "[",
243
+ footnote.gid,
244
+ "]")),
245
+ footnote.make());
246
+ })), {});
308
247
  writer.postInterator.push(FootNotes);
309
248
  });
310
- return function (node, ctx, interator) {
249
+ return (node, ctx, interator) => {
311
250
  // skip empty notes
312
251
  if (node.content.length < 1) {
313
252
  return;
@@ -316,45 +255,42 @@ var mapToReact = function (makeComponent) {
316
255
  writer.gid = 1;
317
256
  }
318
257
  // get foot note id
319
- var gid = writer.gid++;
320
- var fnRefId = "fnref:".concat(gid);
321
- var fnId = "fn:".concat(gid);
258
+ const gid = writer.gid++;
259
+ const fnRefId = `fnref:${gid}`;
260
+ const fnId = `fn:${gid}`;
322
261
  if (!writer.hasOwnProperty('FOOTNOTES')) {
323
262
  writer.FOOTNOTES = [];
324
263
  }
325
264
  writer.FOOTNOTES.push({
326
- gid: gid,
327
- fnRefId: fnRefId,
328
- fnId: fnId,
329
- node: node,
330
- make: function () { return interator(node.content, ctx); }
265
+ gid,
266
+ fnRefId,
267
+ fnId,
268
+ node,
269
+ make: () => { return interator(node.content, ctx); }
331
270
  });
332
- return makeComponent(function (_a) {
333
- var children = _a.children, key = _a.key;
334
- return React.createElement("sup", { key: key, id: fnRefId, className: "footnote" },
335
- React.createElement("a", { href: "#".concat(fnId) },
336
- "[",
337
- gid,
338
- "]"));
339
- }, node);
271
+ return makeComponent(({ children, key }) => React.createElement("sup", { key: key, id: fnRefId, className: "footnote" },
272
+ React.createElement("a", { href: `#${fnId}` },
273
+ "[",
274
+ gid,
275
+ "]")), node);
340
276
  };
341
277
  },
342
278
  'R<>': mkComponent('var'),
343
279
  'T<>': mkComponent('samp'),
344
- 'D<>': function (writer, processor) { return function (node, ctx, interator) {
345
- var synonyms = node.synonyms;
346
- var definition = [node.content[0]];
280
+ 'D<>': (writer, processor) => (node, ctx, interator) => {
281
+ let { synonyms } = node;
282
+ let definition = [node.content[0]];
347
283
  if (synonyms) {
348
284
  definition = synonyms;
349
285
  }
350
286
  if (!writer.hasOwnProperty('DEFINITIONS')) {
351
287
  writer.DEFINITIONS = [];
352
288
  }
353
- writer.DEFINITIONS.push({ definition: definition });
289
+ writer.DEFINITIONS.push({ definition });
354
290
  return makeComponent('dfn', node, interator(node.content, ctx));
355
- }; },
356
- "L<>": setFn(function (node, ctx) {
357
- var meta = node.meta;
291
+ },
292
+ "L<>": (0, handlers_1.setFn)((node, ctx) => {
293
+ let { meta } = node;
358
294
  if (meta === null) {
359
295
  meta = node.content;
360
296
  }
@@ -365,33 +301,27 @@ var mapToReact = function (makeComponent) {
365
301
  if (meta && typeof meta !== 'string' && 'value' in meta) {
366
302
  meta = meta.value;
367
303
  }
368
- return mkComponent(function (_a) {
369
- var children = _a.children, key = _a.key;
370
- return React.createElement("a", { href: meta, key: key }, children);
371
- });
304
+ return mkComponent(({ children, key }) => React.createElement("a", { href: meta, key: key }, children));
372
305
  }),
373
- 'S<>': function (writer, processor) { return function (node, ctx, interator) {
374
- var content = node.content || '';
306
+ 'S<>': (writer, processor) => (node, ctx, interator) => {
307
+ let content = node.content || '';
375
308
  if (typeof content !== 'string' && 'value' in content) {
376
309
  content = content.value;
377
310
  }
378
- var Content = content.split('').map(function (symbol, index) {
311
+ const Content = content.split('').map((symbol, index) => {
379
312
  if (symbol === ' ')
380
313
  return "\u00a0";
381
314
  if (symbol === '\n')
382
315
  return React.createElement("br", { key: index });
383
316
  return symbol;
384
317
  });
385
- return makeComponent(function (_a) {
386
- var children = _a.children, key = _a.key;
387
- return children;
388
- }, {}, Content);
389
- }; },
390
- 'V<>': nodeContent,
391
- 'Z<>': emptyContent(),
318
+ return makeComponent(({ children, key }) => children, {}, Content);
319
+ },
320
+ 'V<>': handlers_1.content,
321
+ 'Z<>': (0, handlers_1.emptyContent)(),
392
322
  'U<>': mkComponent('u'),
393
- 'X<>': function (writer, processor) { return function (node, ctx, interator) {
394
- var entry = node.entry;
323
+ 'X<>': (writer, processor) => (node, ctx, interator) => {
324
+ let { entry } = node;
395
325
  if (entry === null && node.content.length > 0) {
396
326
  //@ts-ignore
397
327
  entry = [node.content[0]];
@@ -401,46 +331,42 @@ var mapToReact = function (makeComponent) {
401
331
  writer.INDEXTERMS = [];
402
332
  }
403
333
  writer.INDEXTERMS.push({
404
- entry: entry
334
+ entry
405
335
  });
406
336
  return interator(node.content, ctx);
407
- }; },
337
+ },
408
338
  // table section
409
- 'table': function (writer, processor) {
410
- return function (node, ctx, interator) {
411
- var conf = makeAttrs(node, ctx);
412
- var attr = { caption: '' };
413
- if (conf.exists('caption')) {
414
- var caption = conf.getFirstValue('caption');
415
- attr.caption = caption;
416
- }
417
- if (typeof node === 'string') {
418
- return node;
419
- }
420
- if (!('content' in node)) {
421
- console.warn('[jsx] no content in node');
422
- return '';
423
- }
424
- return makeComponent(function (_a) {
425
- var key = _a.key, children = _a.children;
426
- return React.createElement("table", { key: key },
427
- React.createElement("caption", { className: "caption" }, attr.caption),
428
- React.createElement("tbody", null, children));
429
- }, node, interator(node.content, __assign({}, ctx)));
430
- };
339
+ 'table': (writer, processor) => (node, ctx, interator) => {
340
+ const conf = (0, config_1.default)(node, ctx);
341
+ let attr = { caption: '' };
342
+ if (conf.exists('caption')) {
343
+ const caption = conf.getFirstValue('caption');
344
+ attr.caption = caption;
345
+ }
346
+ if (typeof node === 'string') {
347
+ return node;
348
+ }
349
+ if (!('content' in node)) {
350
+ console.warn('[jsx] no content in node');
351
+ return '';
352
+ }
353
+ const id = (0, schema_1.getNodeId)(node, ctx);
354
+ return makeComponent(({ key, children }) => {
355
+ return React.createElement("table", { key: key, id: id },
356
+ React.createElement("caption", { className: "caption" }, attr.caption),
357
+ React.createElement("tbody", null, children));
358
+ }, node, interator(node.content, Object.assign({}, ctx)));
431
359
  },
432
- ':separator': emptyContent(),
360
+ ':separator': (0, handlers_1.emptyContent)(),
433
361
  'table_row': mkComponent('tr'),
434
362
  'table_cell': mkComponent('td'),
435
- 'table_head': subUse({
363
+ 'table_head': (0, handlers_1.subUse)({
436
364
  'table_cell': mkComponent('th')
437
365
  }, mkComponent('tr')),
438
- ':list': setFn(function (node, ctx) {
439
- return node.list === 'ordered' ? mkComponent('ol')
440
- : node.list === 'variable' ? mkComponent('dl')
441
- : mkComponent('ul');
442
- }),
443
- 'item:block': function (writer, processor) { return function (node, ctx, interator) {
366
+ ':list': (0, handlers_1.setFn)((node, ctx) => node.list === 'ordered' ? mkComponent('ol')
367
+ : node.list === 'variable' ? mkComponent('dl')
368
+ : mkComponent('ul')),
369
+ 'item:block': (writer, processor) => (node, ctx, interator) => {
444
370
  if (typeof node === 'string') {
445
371
  return node;
446
372
  }
@@ -452,78 +378,64 @@ var mapToReact = function (makeComponent) {
452
378
  if (!(node.content instanceof Array)) {
453
379
  console.error(node);
454
380
  }
455
- var id = getNodeId(node, ctx);
456
- return makeComponent('li', node, interator(node.content, __assign({}, ctx)), { id: id });
457
- }; },
381
+ const id = (0, schema_1.getNodeId)(node, ctx);
382
+ return makeComponent('li', node, interator(node.content, Object.assign({}, ctx)), { id });
383
+ },
458
384
  // table of content
459
- ':toc': setFn(function (node, ctx) {
460
- var tocTitle = node.title;
461
- return mkComponent(function (_a) {
462
- var children = _a.children, key = _a.key;
463
- return React.createElement("div", { className: "toc", key: key },
464
- tocTitle ? React.createElement("div", { className: "toctitle" }, tocTitle) : '',
465
- children);
466
- });
385
+ ':toc': (0, handlers_1.setFn)((node, ctx) => {
386
+ const tocTitle = node.title;
387
+ return mkComponent(({ children, key }) => React.createElement("div", { className: "toc", key: key },
388
+ tocTitle ? React.createElement("div", { className: "toctitle" }, tocTitle) : '',
389
+ children));
467
390
  }),
468
- ':toc-list': setFn(function (node, ctx) {
469
- var level = node.level;
470
- return mkComponent(function (_a) {
471
- var children = _a.children, key = _a.key;
472
- return React.createElement("ul", { className: "toc-list listlevel".concat(level), key: key }, children);
473
- });
391
+ ':toc-list': (0, handlers_1.setFn)((node, ctx) => {
392
+ const { level } = node;
393
+ return mkComponent(({ children, key }) => React.createElement("ul", { className: `toc-list listlevel${level}`, key: key }, children));
474
394
  }),
475
- ':toc-item': subUse({
395
+ ':toc-item': (0, handlers_1.subUse)({
476
396
  // inside head don't wrap into <p>
477
- ':para': nodeContent,
478
- }, setFn(function (node, ctx) {
479
- return mkComponent(function (_a) {
480
- var children = _a.children, key = _a.key;
481
- return React.createElement("li", { className: "toc-item", key: key }, children);
482
- });
397
+ ':para': handlers_1.content,
398
+ }, (0, handlers_1.setFn)((node, ctx) => {
399
+ return mkComponent(({ children, key }) => React.createElement("li", { className: "toc-item", key: key }, children));
483
400
  })),
484
401
  };
485
402
  };
486
- function podlite(children, _a) {
487
- var file = _a.file, _b = _a.plugins, plugins = _b === void 0 ? function () { } : _b, wrapElement = _a.wrapElement, tree = _a.tree;
488
- var args = [];
489
- for (var _i = 2; _i < arguments.length; _i++) {
490
- args[_i - 2] = arguments[_i];
491
- }
492
- var ast = (function (tree) {
403
+ function podlite(children, { file, plugins = () => { }, wrapElement, tree }, ...args) {
404
+ const ast = ((tree) => {
493
405
  if (tree)
494
406
  return tree.interator;
495
- var podlite = podlite_core({ importPlugins: true });
496
- var treeAfterParsed = podlite.parse(children || file);
407
+ let podlite = (0, podlite_1.podlite)({ importPlugins: true });
408
+ let treeAfterParsed = podlite.parse(children || file);
497
409
  return podlite.toAst(treeAfterParsed);
498
410
  })(tree);
499
411
  // const ast = parse( children || content )
500
- var i_key_i = 10000;
501
- var makeComponent = helperMakeReact({ wrapElement: wrapElement });
412
+ let i_key_i = 10000;
413
+ const makeComponent = helperMakeReact({ wrapElement });
502
414
  // TODO: move toJSX to podlite/core
503
415
  // const toJSXPlugins= toAnyRules('toJSX', instance.getPlugins())
504
- var rules = __assign(__assign({}, mapToReact(makeComponent)), plugins(makeComponent));
505
- var writer = new Writer(function (s) {
416
+ const rules = Object.assign(Object.assign({}, mapToReact(makeComponent)), plugins(makeComponent));
417
+ const writer = new writer_1.default((s) => {
506
418
  });
507
- var res = toAny({ processor: parse })
508
- .use({ '*:*': function () { return function (node, ctx, interator) {
419
+ const res = (0, exportAny_1.default)({ processor: pod6_1.parse })
420
+ .use({ '*:*': () => (node, ctx, interator) => {
509
421
  // skip named blocks
510
- if (isNamedBlock(node.name)) {
422
+ if ((0, makeTransformer_1.isNamedBlock)(node.name)) {
511
423
  return null;
512
424
  }
513
- if (isSemanticBlock(node)) {
514
- return makeComponent(function (_a) {
515
- var key = _a.key, children = _a.children;
425
+ if ((0, makeTransformer_1.isSemanticBlock)(node)) {
426
+ return makeComponent(({ key, children }) => {
516
427
  return React.createElement("div", { key: key },
517
428
  React.createElement("h1", { className: node.name, key: key }, node.name),
518
- interator(node.content, __assign({}, ctx)));
519
- }, node, interator(node.content, __assign({}, ctx)));
429
+ interator(node.content, Object.assign({}, ctx)));
430
+ }, node, interator(node.content, Object.assign({}, ctx)));
520
431
  }
521
432
  console.warn('[podlite] Not supported: ' + JSON.stringify(node, null, 2));
522
- return React.createElement('code', { key: ++i_key_i }, "not supported node:".concat(JSON.stringify(node, null, 2)));
523
- }; } })
433
+ return (0, react_1.createElement)('code', { key: ++i_key_i }, `not supported node:${JSON.stringify(node, null, 2)}`);
434
+ } })
524
435
  .use(rules)
525
436
  .run(ast, writer);
526
437
  // union main react elements and post processed via onEnd event
527
438
  return new Array().concat(res.interator, writer.postInterator);
528
439
  }
529
- export default Podlite;
440
+ exports.default = exports.Podlite;
441
+ //# sourceMappingURL=index.js.map