@podlite/to-jsx 0.0.16 → 0.0.17

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/CHANGELOG.md CHANGED
@@ -1,47 +1,79 @@
1
1
  # @podlite/to-jsx
2
2
 
3
3
  ## Upcoming
4
+
5
+ ## 0.0.17
6
+
7
+ - refactor
8
+
4
9
  ## 0.0.16
10
+
5
11
  - refactor
12
+
6
13
  ## 0.0.15
14
+
7
15
  - refactor logic for plugins
16
+
8
17
  ## 0.0.14
18
+
9
19
  - add Strikethrough inline element support
10
20
  - add toJSX support
21
+
11
22
  ## 0.0.13
23
+
12
24
  - update deps
25
+
13
26
  ## 0.0.12
27
+
14
28
  - fix imports
15
29
  - update deps
30
+
16
31
  ## 0.0.11
32
+
17
33
  - use <video> tags for mov/mp4 media
18
34
  - update deps
35
+
19
36
  ## 0.0.10
37
+
20
38
  - fix id for =table
39
+
21
40
  ## 0.0.9
41
+
22
42
  - fix npm
43
+
23
44
  ## 0.0.8
45
+
24
46
  - add support for =Image
25
47
  - add caption for =Diagram
26
48
  - add support for id html attribute
49
+
27
50
  ## 0.0.7
51
+
28
52
  - fix deps
53
+
29
54
  ## 0.0.6
55
+
30
56
  - fix process empty L<>
31
57
 
32
58
  ## 0.0.5
59
+
33
60
  - update deps
34
61
  - declare tree arg
62
+
35
63
  ## 0.0.4
64
+
36
65
  - update deps
66
+
37
67
  ## 0.0.3
68
+
38
69
  - update deps
39
70
 
40
71
  ## 0.0.2
72
+
41
73
  - implement =defn
42
74
  - implemnt =nested
43
75
  - fix dependencies
44
76
 
45
77
  ## 0.0.1
46
- - initial version
47
78
 
79
+ - initial version
package/README.md CHANGED
@@ -1 +1,41 @@
1
- # @podlite/to-jsx
1
+ # @podlite/to-jsx
2
+
3
+ <div align="center">
4
+
5
+ [![Podlite](https://github.com/zag/specs/raw/podlite-specification/assets/podlite_logo_256x256.png)](https://podlite.org)
6
+
7
+ </div>
8
+
9
+ **Podlite is a lightweight block-based markup language designed for flexibility and ease of use.**
10
+
11
+ Unbound by any specific domain, programming language, or concept, Podlite stands out as a universal markup language. It's versatile enough to be successfully implemented across various development fields, from web development to scientific research.
12
+
13
+ Podlite is not limited to any specific application domain, programming language, or concept.
14
+
15
+ In addition, the support for Markdown markup as a standard block adds convenience and allows for the use of familiar syntax for text formatting.
16
+
17
+ One of the key features of Podlite is its extensibility. This allows for defining unique and domain-specific blocks and expanding the language's functionality according to the requirements of your project.
18
+
19
+ Its flexibility makes it an ideal tool for creating documentation, blogs, educational materials, and much more.
20
+
21
+ Podlite aims to provide users with a means for creativity and expressing ideas in a structured form, while ensuring ease of use and high flexibility in content creation.
22
+
23
+ ## Useful links
24
+
25
+ 📖 _Project site_: [podlite.org](https://podlite.org)
26
+
27
+ 📌 _Github_: [github.com/podlite](https://github.com/podlite/) 🤩
28
+
29
+ 🖥️ _Online editor_: [pod6.in](https://pod6.in/)
30
+
31
+ 🖥️ _Desktop editor/viewer_: [github.com/podlite/podlite-desktop](https://github.com/podlite/podlite-desktop) - the viewer and editor of `.podlite` and `.pod6` files for Windows, Linux and Mac.
32
+
33
+ 📚 _Podlite for web_ - static site generator: [github.com/podlite/podlite-web](https://github.com/podlite/podlite-web)
34
+
35
+ ## AUTHOR
36
+
37
+ Copyright (c) 2021-2024 Aliaksandr Zahatski
38
+
39
+ ## License
40
+
41
+ Released under a MIT License.
package/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  'use strict'
2
- module.exports = require('./lib')
2
+ module.exports = require('./lib')
package/jest.config.js CHANGED
@@ -1,2 +1 @@
1
-
2
1
  module.exports = require('../../jest.config')
@@ -1 +1 @@
1
- {"extends": "../../jest.tsconfig.json"}
1
+ { "extends": "../../jest.tsconfig.json" }
package/lib/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import * as React from 'react';
2
- import { PodliteExport } from 'podlite';
3
- import { PodNode } from '@podlite/schema';
2
+ import { PodNode, PodliteExport } from '@podlite/schema';
4
3
  export declare type CreateElement = typeof React.createElement;
5
4
  export interface WrapElement {
6
5
  (node: PodNode, children: React.ReactChild, ctx: any): JSX.Element;
@@ -16,9 +15,9 @@ export declare const Podlite: React.FC<{
16
15
  export declare const TestPodlite: ({ children, ...options }: {
17
16
  [x: string]: any;
18
17
  children: any;
19
- }) => JSX.Element;
20
- export declare const makeTestPodlite: (podlite?: any) => ({ children, ...options }: {
18
+ }) => React.JSX.Element;
19
+ export declare const makeTestPodlite: (podlite?: import("@podlite/schema").Podlite) => ({ children, ...options }: {
21
20
  [x: string]: any;
22
21
  children: any;
23
- }) => JSX.Element;
22
+ }) => React.JSX.Element;
24
23
  export default Podlite;
package/lib/index.js CHANGED
@@ -1,26 +1,12 @@
1
- "use strict";
2
- var __rest = (this && this.__rest) || function (s, e) {
3
- var t = {};
4
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
- t[p] = s[p];
6
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
- t[p[i]] = s[p[i]];
10
- }
11
- return t;
12
- };
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.makeTestPodlite = exports.TestPodlite = exports.Podlite = void 0;
15
- const React = require("react");
16
- const react_1 = require("react");
17
- const podlite_1 = require("podlite");
18
- const schema_1 = require("@podlite/schema");
19
- const schema_2 = require("@podlite/schema");
1
+ import * as React from 'react';
2
+ import { createElement } from 'react';
3
+ import { podlite as podlite_core } from 'podlite';
4
+ import { getNodeId, parse, makeAttrs, emptyContent, content as nodeContent, setFn, subUse, toAny, isNamedBlock, isSemanticBlock, Writer, toAnyRules, frozenIds, } from '@podlite/schema';
5
+ import { pluginCleanLocation as clean_plugin } from '@podlite/schema';
20
6
  const helperMakeReact = ({ wrapElement }) => {
21
7
  let i_key_i = 0;
22
8
  let mapByType = {};
23
- const getIdForNode = ({ type = "notype", name = "noname" }) => {
9
+ const getIdForNode = ({ type = 'notype', name = 'noname' }) => {
24
10
  const type_idx = `${type}_${name}`;
25
11
  if (!mapByType[type_idx]) {
26
12
  mapByType[type_idx] = 0;
@@ -33,11 +19,11 @@ const helperMakeReact = ({ wrapElement }) => {
33
19
  if (typeof node == 'string') {
34
20
  return node;
35
21
  }
36
- const attr = __rest(node, []);
22
+ const { ...attr } = node;
37
23
  const key = 'type' in node && node.type ? getIdForNode(node) : ++i_key_i;
38
24
  const result = typeof src === 'function'
39
- ? src(Object.assign(Object.assign({}, attr), { key, children }), children)
40
- : (0, react_1.createElement)(src, Object.assign(Object.assign({}, extraProps), { key }), children);
25
+ ? src({ ...attr, key, children }, children)
26
+ : createElement(src, { ...extraProps, key }, children);
41
27
  // // create react element and pass key
42
28
  // if (!isValidElementType(src)) {
43
29
  // throw new Error(`Bad React element for ${ruleName} rule `)
@@ -48,48 +34,45 @@ const helperMakeReact = ({ wrapElement }) => {
48
34
  return result;
49
35
  };
50
36
  };
51
- const Podlite = (_a) => {
52
- var { children } = _a, options = __rest(_a, ["children"]);
37
+ export const Podlite = ({ children, ...options }) => {
53
38
  const result = podlite(children, options);
54
39
  return result;
55
40
  };
56
- exports.Podlite = Podlite;
57
41
  const mapToReact = (makeComponent) => {
58
- const mkComponent = (src) => (writer, processor) => (node, ctx, interator) => {
59
- var _a;
42
+ const mkComponent = src => (writer, processor) => (node, ctx, interator) => {
60
43
  // prepare extraProps for createElement
61
44
  // add id attribute if exists
62
- const id = (_a = (0, schema_1.getNodeId)(node, ctx)) === null || _a === void 0 ? void 0 : _a.replace(/\s/g, '-');
45
+ const id = getNodeId(node, ctx)?.replace(/\s/g, '-');
63
46
  // check if node.content defined
64
- return makeComponent(src, node, 'content' in node ? interator(node.content, Object.assign({}, ctx)) : [], { id }, ctx);
47
+ return makeComponent(src, node, 'content' in node ? interator(node.content, { ...ctx }) : [], { id }, ctx);
65
48
  };
66
49
  // Handle nested block and :nested block attribute
67
50
  const handleNested = (defaultHandler, implicitLevel) => {
68
51
  return (writer, processor) => {
69
52
  const defaultHandlerInited = defaultHandler(writer, processor);
70
53
  return (node, ctx, interator) => {
71
- const nesting = (0, schema_1.makeAttrs)(node, ctx).getFirstValue('nested') || implicitLevel;
54
+ const nesting = makeAttrs(node, ctx).getFirstValue('nested') || implicitLevel;
72
55
  const children = defaultHandlerInited(node, ctx, interator);
73
56
  // if no nesting needs - simply return children
74
57
  if (!nesting) {
75
58
  return children;
76
59
  }
77
60
  const arr = [...Array(nesting).keys()];
78
- return arr.reduce((acc) => makeComponent('blockquote', node, acc), children);
61
+ return arr.reduce(acc => makeComponent('blockquote', node, acc), children);
79
62
  };
80
63
  };
81
64
  };
82
65
  return {
83
- 'pod': mkComponent('div'),
84
- 'root': schema_1.content,
85
- 'data': (0, schema_1.emptyContent)(),
86
- ':ambient': (0, schema_1.emptyContent)(),
87
- ':code': mkComponent(({ children, key }) => React.createElement("code", { key: key },
88
- React.createElement("pre", null, children))),
89
- 'code': mkComponent(({ children, key }) => React.createElement("code", { key: key },
90
- React.createElement("pre", null, children))),
91
- 'image': schema_1.content,
92
- ':image': (0, schema_1.setFn)((node, ctx) => {
66
+ pod: mkComponent('div'),
67
+ root: nodeContent,
68
+ data: emptyContent(),
69
+ ':ambient': emptyContent(),
70
+ ':code': mkComponent(({ children, key }) => (React.createElement("code", { key: key },
71
+ React.createElement("pre", null, children)))),
72
+ code: mkComponent(({ children, key }) => (React.createElement("code", { key: key },
73
+ React.createElement("pre", null, children)))),
74
+ image: nodeContent,
75
+ ':image': setFn((node, ctx) => {
93
76
  return mkComponent(({ children, key }) => React.createElement("img", { key: key, src: node.src, alt: node.alt }));
94
77
  }),
95
78
  ':text': (writer, processor) => (node, ctx, interator) => {
@@ -98,46 +81,45 @@ const mapToReact = (makeComponent) => {
98
81
  ':verbatim': (writer, processor) => (node, ctx, interator) => {
99
82
  return node.value;
100
83
  },
101
- 'head:block': (0, schema_1.subUse)({
84
+ 'head:block': subUse({
102
85
  // inside head don't wrap into <p>
103
- ':para': schema_1.content,
104
- }, (0, schema_1.setFn)((node, ctx) => {
105
- var _a;
86
+ ':para': nodeContent,
87
+ }, setFn((node, ctx) => {
106
88
  const { level } = node;
107
- const id = (_a = (0, schema_1.getNodeId)(node, ctx)) === null || _a === void 0 ? void 0 : _a.replace(/\s/g, '-');
108
- return mkComponent(({ level, children, key }) => (0, react_1.createElement)(`h${level}`, { key, id }, children));
89
+ const id = getNodeId(node, ctx)?.replace(/\s/g, '-');
90
+ return mkComponent(({ level, children, key }) => createElement(`h${level}`, { key, id }, children));
109
91
  })),
110
- ':blankline': (0, schema_1.emptyContent)(),
92
+ ':blankline': emptyContent(),
111
93
  ':para': mkComponent('p'),
112
- 'para': mkComponent('div'),
113
- 'comment:block': (0, schema_1.emptyContent)(),
114
- 'defn': (0, schema_1.subUse)([
94
+ para: mkComponent('div'),
95
+ 'comment:block': emptyContent(),
96
+ defn: subUse([
115
97
  // to avoid overlap para blocks handlers
116
98
  // define general :para at first
117
99
  { ':para': mkComponent('dd') },
118
100
  { 'term:para': mkComponent('dt') },
119
- ], schema_1.content),
120
- "nested": handleNested(schema_1.content, 1),
121
- 'output': mkComponent(({ children, key }) => React.createElement("pre", { key: key },
122
- React.createElement("samp", null, children))),
123
- 'input': mkComponent(({ children, key }) => React.createElement("pre", { key: key },
124
- React.createElement("kbd", null, children))),
125
- // Directives
126
- ':config': (0, schema_1.setFn)((node, ctx) => {
101
+ ], nodeContent),
102
+ nested: handleNested(nodeContent, 1),
103
+ output: mkComponent(({ children, key }) => (React.createElement("pre", { key: key },
104
+ React.createElement("samp", null, children)))),
105
+ input: mkComponent(({ children, key }) => (React.createElement("pre", { key: key },
106
+ React.createElement("kbd", null, children)))),
107
+ // Directives
108
+ ':config': setFn((node, ctx) => {
127
109
  // setup context
128
110
  if (!ctx.hasOwnProperty('config'))
129
111
  ctx.config = {};
130
112
  //collect configs in context
131
113
  ctx.config[node.name] = node.config;
132
- return (0, schema_1.emptyContent)();
114
+ return emptyContent();
133
115
  }),
134
- ':alias': (0, schema_1.setFn)((node, ctx) => {
116
+ ':alias': setFn((node, ctx) => {
135
117
  // set alias
136
118
  if (!ctx.hasOwnProperty('alias'))
137
119
  ctx.alias = {};
138
120
  //collect configs in context
139
121
  ctx.alias[node.name] = node.replacement;
140
- return (0, schema_1.emptyContent)();
122
+ return emptyContent();
141
123
  }),
142
124
  // Formatting codes
143
125
  'A<>': (writer, processor) => (node, ctx, interator) => {
@@ -156,7 +138,7 @@ const mapToReact = (makeComponent) => {
156
138
  const src = ctx.alias[term].join('\n');
157
139
  const tree_1 = processor(src);
158
140
  // now clean locations
159
- const tree = (0, schema_2.pluginCleanLocation)()(tree_1);
141
+ const tree = clean_plugin()(tree_1);
160
142
  if (tree[0].type === 'para') {
161
143
  return interator(tree[0].content, ctx);
162
144
  }
@@ -169,24 +151,27 @@ const mapToReact = (makeComponent) => {
169
151
  'C<>': mkComponent('code'),
170
152
  'E<>': (writer, processor) => (node, ctx, interator) => {
171
153
  if ('content' in node && Array.isArray(node.content))
172
- return node.content.filter(e => e && e.type == 'number').map(element => {
154
+ return node.content
155
+ .filter(e => e && e.type == 'number')
156
+ .map(element => {
173
157
  return String.fromCharCode(element.value);
174
- }).join('');
158
+ })
159
+ .join('');
175
160
  },
176
161
  'I<>': mkComponent('i'),
177
162
  'K<>': mkComponent('kbd'),
178
163
  /**
179
- * CSS rules for footnotes
180
-
181
- .footnote a {
182
- text-decoration: none;
183
- }
184
- .footnotes {
185
- border-top-style: solid;
186
- border-top-width: 1px;
187
- border-top-color: #eee;
188
- }
189
- */
164
+ * CSS rules for footnotes
165
+
166
+ .footnote a {
167
+ text-decoration: none;
168
+ }
169
+ .footnotes {
170
+ border-top-style: solid;
171
+ border-top-width: 1px;
172
+ border-top-color: #eee;
173
+ }
174
+ */
190
175
  'N<>': (writer, processor) => {
191
176
  writer.addListener('end', () => {
192
177
  if (!writer.hasOwnProperty('FOOTNOTES')) {
@@ -199,15 +184,15 @@ const mapToReact = (makeComponent) => {
199
184
  if (!writer.hasOwnProperty('postInterator')) {
200
185
  writer.postInterator = [];
201
186
  }
202
- const FootNotes = makeComponent(({ children, key }) => React.createElement("div", { key: `${key}_FOOTNOTES`, className: "footnotes" }, footnotes.map((footnote, id) => {
203
- return React.createElement("p", { key: id },
187
+ const FootNotes = makeComponent(({ children, key }) => (React.createElement("div", { key: `${key}_FOOTNOTES`, className: "footnotes" }, footnotes.map((footnote, id) => {
188
+ return (React.createElement("p", { key: id },
204
189
  React.createElement("sup", { id: footnote.fnId, className: "footnote" },
205
190
  React.createElement("a", { href: `#${footnote.fnRefId}` },
206
191
  "[",
207
192
  footnote.gid,
208
193
  "]")),
209
- footnote.make());
210
- })), {});
194
+ footnote.make()));
195
+ }))), {});
211
196
  writer.postInterator.push(FootNotes);
212
197
  });
213
198
  return (node, ctx, interator) => {
@@ -230,13 +215,15 @@ const mapToReact = (makeComponent) => {
230
215
  fnRefId,
231
216
  fnId,
232
217
  node,
233
- make: () => { return interator(node.content, ctx); }
218
+ make: () => {
219
+ return interator(node.content, ctx);
220
+ },
234
221
  });
235
- return makeComponent(({ children, key }) => React.createElement("sup", { key: key, id: fnRefId, className: "footnote" },
222
+ return makeComponent(({ children, key }) => (React.createElement("sup", { key: key, id: fnRefId, className: "footnote" },
236
223
  React.createElement("a", { href: `#${fnId}` },
237
224
  "[",
238
225
  gid,
239
- "]")), node);
226
+ "]"))), node);
240
227
  };
241
228
  },
242
229
  'R<>': mkComponent('var'),
@@ -253,7 +240,7 @@ const mapToReact = (makeComponent) => {
253
240
  writer.DEFINITIONS.push({ definition });
254
241
  return makeComponent('dfn', node, interator(node.content, ctx));
255
242
  },
256
- "L<>": (0, schema_1.setFn)((node, ctx) => {
243
+ 'L<>': setFn((node, ctx) => {
257
244
  let { meta } = node;
258
245
  if (meta === null) {
259
246
  meta = node.content;
@@ -265,7 +252,7 @@ const mapToReact = (makeComponent) => {
265
252
  if (meta && typeof meta !== 'string' && 'value' in meta) {
266
253
  meta = meta.value;
267
254
  }
268
- return mkComponent(({ children, key }) => React.createElement("a", { href: meta, key: key }, children));
255
+ return mkComponent(({ children, key }) => (React.createElement("a", { href: meta, key: key }, children)));
269
256
  }),
270
257
  'S<>': (writer, processor) => (node, ctx, interator) => {
271
258
  let content = node.content || '';
@@ -274,15 +261,15 @@ const mapToReact = (makeComponent) => {
274
261
  }
275
262
  const Content = content.split('').map((symbol, index) => {
276
263
  if (symbol === ' ')
277
- return "\u00a0";
264
+ return '\u00a0';
278
265
  if (symbol === '\n')
279
266
  return React.createElement("br", { key: index });
280
267
  return symbol;
281
268
  });
282
269
  return makeComponent(({ children, key }) => children, {}, Content);
283
270
  },
284
- 'V<>': schema_1.content,
285
- 'Z<>': (0, schema_1.emptyContent)(),
271
+ 'V<>': nodeContent,
272
+ 'Z<>': emptyContent(),
286
273
  'U<>': mkComponent('u'),
287
274
  'X<>': (writer, processor) => (node, ctx, interator) => {
288
275
  let { entry } = node;
@@ -295,15 +282,14 @@ const mapToReact = (makeComponent) => {
295
282
  writer.INDEXTERMS = [];
296
283
  }
297
284
  writer.INDEXTERMS.push({
298
- entry
285
+ entry,
299
286
  });
300
287
  return interator(node.content, ctx);
301
288
  },
302
289
  'Delete<>': mkComponent('del'),
303
290
  // table section
304
- 'table': (writer, processor) => (node, ctx, interator) => {
305
- var _a;
306
- const conf = (0, schema_1.makeAttrs)(node, ctx);
291
+ table: (writer, processor) => (node, ctx, interator) => {
292
+ const conf = makeAttrs(node, ctx);
307
293
  let attr = { caption: '' };
308
294
  if (conf.exists('caption')) {
309
295
  const caption = conf.getFirstValue('caption');
@@ -316,24 +302,21 @@ const mapToReact = (makeComponent) => {
316
302
  console.warn('[jsx] no content in node');
317
303
  return '';
318
304
  }
319
- const id = (_a = (0, schema_1.getNodeId)(node, ctx)) === null || _a === void 0 ? void 0 : _a.replace(/\s/g, '-');
305
+ const id = getNodeId(node, ctx)?.replace(/\s/g, '-');
320
306
  return makeComponent(({ key, children }) => {
321
- return React.createElement("table", { key: key, id: id },
307
+ return (React.createElement("table", { key: key, id: id },
322
308
  React.createElement("caption", { className: "caption" }, attr.caption),
323
- React.createElement("tbody", null, children));
324
- }, node, interator(node.content, Object.assign({}, ctx)));
309
+ React.createElement("tbody", null, children)));
310
+ }, node, interator(node.content, { ...ctx }));
325
311
  },
326
- ':separator': (0, schema_1.emptyContent)(),
327
- 'table_row': mkComponent('tr'),
328
- 'table_cell': mkComponent('td'),
329
- 'table_head': (0, schema_1.subUse)({
330
- 'table_cell': mkComponent('th')
312
+ ':separator': emptyContent(),
313
+ table_row: mkComponent('tr'),
314
+ table_cell: mkComponent('td'),
315
+ table_head: subUse({
316
+ table_cell: mkComponent('th'),
331
317
  }, mkComponent('tr')),
332
- ':list': (0, schema_1.setFn)((node, ctx) => node.list === 'ordered' ? mkComponent('ol')
333
- : node.list === 'variable' ? mkComponent('dl')
334
- : mkComponent('ul')),
318
+ ':list': setFn((node, ctx) => node.list === 'ordered' ? mkComponent('ol') : node.list === 'variable' ? mkComponent('dl') : mkComponent('ul')),
335
319
  'item:block': (writer, processor) => (node, ctx, interator) => {
336
- var _a;
337
320
  if (typeof node === 'string') {
338
321
  return node;
339
322
  }
@@ -345,83 +328,84 @@ const mapToReact = (makeComponent) => {
345
328
  if (!(node.content instanceof Array)) {
346
329
  console.error(node);
347
330
  }
348
- const id = (_a = (0, schema_1.getNodeId)(node, ctx)) === null || _a === void 0 ? void 0 : _a.replace(/\s/g, '-');
349
- return makeComponent('li', node, interator(node.content, Object.assign({}, ctx)), { id });
331
+ const id = getNodeId(node, ctx)?.replace(/\s/g, '-');
332
+ return makeComponent('li', node, interator(node.content, { ...ctx }), { id });
350
333
  },
351
334
  // table of content
352
- ':toc': (0, schema_1.setFn)((node, ctx) => {
335
+ ':toc': setFn((node, ctx) => {
353
336
  const tocTitle = node.title;
354
- return mkComponent(({ children, key }) => React.createElement("div", { className: "toc", key: key },
337
+ return mkComponent(({ children, key }) => (React.createElement("div", { className: "toc", key: key },
355
338
  tocTitle ? React.createElement("div", { className: "toctitle" }, tocTitle) : '',
356
- children));
339
+ children)));
357
340
  }),
358
- ':toc-list': (0, schema_1.setFn)((node, ctx) => {
341
+ ':toc-list': setFn((node, ctx) => {
359
342
  const { level } = node;
360
- return mkComponent(({ children, key }) => React.createElement("ul", { className: `toc-list listlevel${level}`, key: key }, children));
343
+ return mkComponent(({ children, key }) => (React.createElement("ul", { className: `toc-list listlevel${level}`, key: key }, children)));
361
344
  }),
362
- ':toc-item': (0, schema_1.subUse)({
345
+ ':toc-item': subUse({
363
346
  // inside head don't wrap into <p>
364
- ':para': schema_1.content,
365
- }, (0, schema_1.setFn)((node, ctx) => {
366
- return mkComponent(({ children, key }) => React.createElement("li", { className: "toc-item", key: key }, children));
347
+ ':para': nodeContent,
348
+ }, setFn((node, ctx) => {
349
+ return mkComponent(({ children, key }) => (React.createElement("li", { className: "toc-item", key: key }, children)));
367
350
  })),
368
351
  };
369
352
  };
370
- function podlite(children, { file, plugins = () => { }, wrapElement, tree }, ...args) {
371
- const ast = ((tree) => {
353
+ function podlite(children, { file, plugins = () => { }, wrapElement, tree, }, ...args) {
354
+ const ast = (tree => {
372
355
  if (tree)
373
356
  return tree.interator;
374
- let podlite = (0, podlite_1.podlite)({ importPlugins: true });
357
+ let podlite = podlite_core({ importPlugins: true });
375
358
  let treeAfterParsed = podlite.parse(children || file);
376
359
  return podlite.toAst(treeAfterParsed);
377
360
  })(tree);
378
361
  // const ast = parse( children || content )
379
362
  let i_key_i = 10000;
380
363
  const makeComponent = helperMakeReact({ wrapElement });
381
- const jsxPlugins = (0, podlite_1.toAnyRules)('toJSX', (0, podlite_1.podlite)({ importPlugins: true }).getPlugins());
364
+ const jsxPlugins = toAnyRules('toJSX', podlite_core({ importPlugins: true }).getPlugins());
382
365
  // initialize each plugin
383
366
  const jsxPluginInited = Object.fromEntries(Object.entries(jsxPlugins).map(([key, value]) => [key, value(makeComponent)]));
384
- const rules = Object.assign(Object.assign(Object.assign({}, mapToReact(makeComponent)), plugins(makeComponent)), jsxPluginInited);
385
- const writer = new schema_1.Writer((s) => {
386
- });
387
- const res = (0, schema_1.toAny)({ processor: schema_1.parse })
388
- .use({ '*:*': () => (node, ctx, interator) => {
367
+ const rules = {
368
+ ...mapToReact(makeComponent),
369
+ ...plugins(makeComponent),
370
+ ...jsxPluginInited,
371
+ };
372
+ const writer = new Writer(s => { });
373
+ const res = toAny({ processor: parse })
374
+ .use({
375
+ '*:*': () => (node, ctx, interator) => {
389
376
  // skip named blocks
390
- if ((0, schema_1.isNamedBlock)(node.name)) {
377
+ if (isNamedBlock(node.name)) {
391
378
  return null;
392
379
  }
393
- if ((0, schema_1.isSemanticBlock)(node)) {
380
+ if (isSemanticBlock(node)) {
394
381
  return makeComponent(({ key, children }) => {
395
- return React.createElement("div", { key: key },
382
+ return (React.createElement("div", { key: key },
396
383
  React.createElement("h1", { className: node.name, key: key }, node.name),
397
- interator(node.content, Object.assign({}, ctx)));
398
- }, node, interator(node.content, Object.assign({}, ctx)));
384
+ interator(node.content, { ...ctx })));
385
+ }, node, interator(node.content, { ...ctx }));
399
386
  }
400
387
  console.warn('[podlite] Not supported: ' + JSON.stringify(node, null, 2));
401
- return (0, react_1.createElement)('code', { key: ++i_key_i }, `not supported node:${JSON.stringify(node, null, 2)}`);
402
- } })
388
+ return createElement('code', { key: ++i_key_i }, `not supported node:${JSON.stringify(node, null, 2)}`);
389
+ },
390
+ })
403
391
  .use(rules)
404
392
  .run(ast, writer);
405
393
  // union main react elements and post processed via onEnd event
406
394
  return new Array().concat(res.interator, writer.postInterator);
407
395
  }
408
396
  // this is a helper function for using in unit test
409
- const TestPodlite = (_a) => {
410
- var { children } = _a, options = __rest(_a, ["children"]);
411
- let podlite = (0, podlite_1.podlite)({ importPlugins: true });
397
+ export const TestPodlite = ({ children, ...options }) => {
398
+ let podlite = podlite_core({ importPlugins: true });
412
399
  // its replace all ids with "id"
413
- let treeAfterParsed = (0, podlite_1.frozenIds)()(podlite.parse(children));
400
+ let treeAfterParsed = frozenIds()(podlite.parse(children));
414
401
  const tree = podlite.toAst(treeAfterParsed);
415
- return (React.createElement(exports.Podlite, Object.assign({}, Object.assign(Object.assign({ children }, options), { tree: { interator: tree } }))));
402
+ return React.createElement(Podlite, { ...{ children, ...options, tree: { interator: tree } } });
416
403
  };
417
- exports.TestPodlite = TestPodlite;
418
- const makeTestPodlite = (podlite = (0, podlite_1.podlite)({ importPlugins: true })) => (_a) => {
419
- var { children } = _a, options = __rest(_a, ["children"]);
404
+ export const makeTestPodlite = (podlite = podlite_core({ importPlugins: true })) => ({ children, ...options }) => {
420
405
  let treeAfterParsed = podlite.parse(children);
421
406
  // its replace all ids with "id"
422
- const tree = (0, podlite_1.frozenIds)()(podlite.toAst(treeAfterParsed));
423
- return (React.createElement(exports.Podlite, Object.assign({}, Object.assign(Object.assign({ children }, options), { tree: { interator: tree } }))));
407
+ const tree = frozenIds()(podlite.toAst(treeAfterParsed));
408
+ return React.createElement(Podlite, { ...{ children, ...options, tree: { interator: tree } } });
424
409
  };
425
- exports.makeTestPodlite = makeTestPodlite;
426
- exports.default = exports.Podlite;
410
+ export default Podlite;
427
411
  //# sourceMappingURL=index.js.map