@canopycanopycanopy/b-ber-grammar-section 1.2.16 → 2.0.2

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 (2) hide show
  1. package/dist/index.js +24 -57
  2. package/package.json +10 -9
package/dist/index.js CHANGED
@@ -1,90 +1,60 @@
1
1
  "use strict";
2
2
 
3
3
  var _Object$keys = require("@babel/runtime-corejs3/core-js-stable/object/keys");
4
-
5
4
  var _Object$getOwnPropertySymbols = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols");
6
-
7
5
  var _filterInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/filter");
8
-
9
6
  var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor");
10
-
11
7
  var _forEachInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/for-each");
12
-
13
8
  var _Object$getOwnPropertyDescriptors = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors");
14
-
15
9
  var _Object$defineProperties = require("@babel/runtime-corejs3/core-js-stable/object/define-properties");
16
-
17
10
  var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
18
-
19
11
  var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
20
-
21
12
  _Object$defineProperty(exports, "__esModule", {
22
13
  value: true
23
14
  });
24
-
25
15
  exports.default = void 0;
26
-
27
16
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
28
-
29
17
  var _from = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/from"));
30
-
31
18
  var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
32
-
33
19
  var _trim = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/trim"));
34
-
35
20
  var _lodash = _interopRequireDefault(require("lodash.find"));
36
-
37
21
  var _State = _interopRequireDefault(require("@canopycanopycanopy/b-ber-lib/State"));
38
-
39
22
  var _bBerLib = require("@canopycanopycanopy/b-ber-lib");
40
-
41
23
  var _bBerShapesDirectives = require("@canopycanopycanopy/b-ber-shapes-directives");
42
-
43
24
  var _bBerLogger = _interopRequireDefault(require("@canopycanopycanopy/b-ber-logger"));
44
-
45
25
  var _bBerParserSection = _interopRequireDefault(require("@canopycanopycanopy/b-ber-parser-section"));
46
-
47
26
  var _bBerGrammarRenderer = _interopRequireDefault(require("@canopycanopycanopy/b-ber-grammar-renderer"));
48
-
49
27
  var _bBerGrammarAttributes = require("@canopycanopycanopy/b-ber-grammar-attributes");
50
-
51
- function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); if (enumerableOnly) symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
52
-
53
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context2; _forEachInstanceProperty(_context2 = ownKeys(Object(source), true)).call(_context2, function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (_Object$getOwnPropertyDescriptors) { _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)); } else { var _context3; _forEachInstanceProperty(_context3 = ownKeys(Object(source))).call(_context3, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } } return target; }
54
-
55
- // this matches *all* container-type directives, and outputs the appropriate
28
+ function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
29
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context2, _context3; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context2 = ownKeys(Object(source), !0)).call(_context2, function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context3 = ownKeys(Object(source))).call(_context3, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
30
+ // This matches *all* container-type directives, and outputs the appropriate
56
31
  // HTML based on user-defined attributes
57
- const containers = (0, _from.default)(_bBerShapesDirectives.BLOCK_DIRECTIVES).join('|'); // treat `exit` like an opening marker since we're using it as such
32
+ const containers = (0, _from.default)(_bBerShapesDirectives.BLOCK_DIRECTIVES).join('|');
58
33
 
34
+ // Treat `exit` like an opening marker
59
35
  const MARKER_OPEN_RE = new RegExp(`^(${containers}|exit)(?::([^\\s]+)(\\s.*)?)?$`);
60
- const MARKER_CLOSE_RE = /(exit)(?::([^\s]+))?/; // since `context` needs to be available in this `render` method, we curry it
61
- // in and pass the resulting function to the `createRenderer` below. we also
62
- // set a default for `context` since we'll need some of its properties during
63
- // testing
36
+ const MARKER_CLOSE_RE = /(exit)(?::([^\s]+))?/;
37
+
38
+ // `context` must be available in this `render` method and is passed
39
+ // into `createRenderer` below. Default for `context` is set for use
40
+ // during tests
64
41
 
65
42
  function isGallery(directive) {
66
43
  return directive && directive.type === 'gallery' && (_State.default.build === 'web' || _State.default.build === 'reader');
67
44
  }
68
-
69
45
  function isSpread(directive) {
70
46
  return directive && directive.type === 'spread' && (_State.default.build === 'web' || _State.default.build === 'reader');
71
47
  }
72
-
73
48
  function handleExitDirective(token) {
74
49
  const [, type, id] = token;
75
-
76
50
  _bBerLogger.default.debug(`exit directive [${id}]`);
77
-
78
51
  const comment = _bBerLib.Html.comment(`END: section:${type}#${(0, _bBerGrammarAttributes.htmlId)(id)}`);
79
-
80
52
  const directive = (0, _lodash.default)(_State.default.cursor, {
81
53
  id
82
54
  });
83
-
84
55
  _State.default.remove('cursor', {
85
56
  id
86
57
  });
87
-
88
58
  if (isGallery(directive)) {
89
59
  // prettier-ignore
90
60
  return `</div>
@@ -92,70 +62,67 @@ function handleExitDirective(token) {
92
62
  </div>
93
63
  </section>${comment}`;
94
64
  }
95
-
96
65
  if (isSpread(directive)) {
97
66
  return `</div>
98
- </div>${comment}`;
99
- }
67
+ </div>
68
+
69
+ ${_State.default.build === 'reader' ? `<!-- Empty node required for spread markers -->
70
+ <div></div>` : ''}
100
71
 
72
+ ${comment}`;
73
+ }
101
74
  return `</section>${comment}`;
102
75
  }
103
-
104
76
  function openElement(token, fileName, lineNumber) {
105
- // destructure the attributes from matches, omitting `matches[0]` since
77
+ // Destructure the attributes from matches, omitting `matches[0]` since
106
78
  // we're only interested in the captures
107
79
  const [, type, id, attr] = token;
108
-
109
80
  _bBerLogger.default.debug(`open directive [${id}]`);
110
-
111
81
  const comment = _bBerLib.Html.comment(`START: section:${type}#${(0, _bBerGrammarAttributes.htmlId)(id)}; ${fileName}:${lineNumber}`);
112
-
113
82
  const attrs = (0, _bBerGrammarAttributes.attributes)(attr, type, {
114
83
  fileName,
115
84
  lineNumber
116
85
  });
117
86
  return `${comment}<section id="${(0, _bBerGrammarAttributes.htmlId)(id)}"${attrs}>`;
118
87
  }
119
-
120
88
  function closeElement(marker) {
121
89
  // tokens `nesting` prop is -1. we should be closing the html element
122
90
  // here, but probably have done so above since we're treating `exit`
123
91
  // directives as openers. check to see if the element has in fact been
124
92
  // closed
93
+
125
94
  const token = marker.split(':');
126
95
  if (token.length < 2) return '';
127
96
  const [, id] = token;
128
97
  if (!_State.default.contains('cursor', {
129
98
  id
130
- })) return ''; // its id still exists in state, so it's open. force close here
99
+ })) return '';
131
100
 
101
+ // its id still exists in state, so it's open. force close here
132
102
  const comment = _bBerLib.Html.comment(`END: section:#${(0, _bBerGrammarAttributes.htmlId)(id)}`);
103
+ const result = `</section>${comment}`;
133
104
 
134
- const result = `</section>${comment}`; // remove the id
135
-
105
+ // remove the id
136
106
  _State.default.remove('cursor', {
137
107
  id
138
108
  });
139
-
140
109
  return result;
141
110
  }
142
-
143
111
  const render = ({
144
112
  context = {}
145
113
  }) => (tokens, index) => {
146
114
  var _context;
147
-
148
115
  const token = tokens[index];
149
116
  const lineNumber = (0, _map.default)(token) ? (0, _map.default)(token)[0] : null;
150
117
  const fileName = `_markdown/${context.fileName}.md`;
151
118
  const marker = (0, _trim.default)(_context = token.info).call(_context);
152
- if (token.nesting !== 1) return closeElement(marker); // token open, we ignore closing tokens and let `exit` handle those
119
+ if (token.nesting !== 1) return closeElement(marker);
153
120
 
121
+ // token open, we ignore closing tokens and let `exit` handle those
154
122
  const tokenClose = marker.match(MARKER_CLOSE_RE);
155
123
  const tokenOpen = marker.match(MARKER_OPEN_RE);
156
124
  return tokenClose ? handleExitDirective(tokenClose) : openElement(tokenOpen, fileName, lineNumber);
157
125
  };
158
-
159
126
  var _default = {
160
127
  plugin: _bBerParserSection.default,
161
128
  name: 'section',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canopycanopycanopy/b-ber-grammar-section",
3
- "version": "1.2.16",
3
+ "version": "2.0.2",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -20,16 +20,17 @@
20
20
  "@babel/cli": "^7.10.5",
21
21
  "@babel/core": "^7.10.5",
22
22
  "@babel/preset-env": "^7.10.4",
23
+ "browserslist": "^4.17.4",
23
24
  "jest": "^26.6.3",
24
- "rimraf": "^2.6.3"
25
+ "rimraf": "^2.7.1"
25
26
  },
26
27
  "dependencies": {
27
- "@canopycanopycanopy/b-ber-grammar-attributes": "1.2.16",
28
- "@canopycanopycanopy/b-ber-grammar-renderer": "1.2.16",
29
- "@canopycanopycanopy/b-ber-lib": "1.2.16",
30
- "@canopycanopycanopy/b-ber-logger": "1.2.16",
31
- "@canopycanopycanopy/b-ber-parser-section": "1.2.16",
32
- "@canopycanopycanopy/b-ber-shapes-directives": "1.2.16",
28
+ "@canopycanopycanopy/b-ber-grammar-attributes": "2.0.2",
29
+ "@canopycanopycanopy/b-ber-grammar-renderer": "2.0.2",
30
+ "@canopycanopycanopy/b-ber-lib": "2.0.2",
31
+ "@canopycanopycanopy/b-ber-logger": "2.0.2",
32
+ "@canopycanopycanopy/b-ber-parser-section": "2.0.2",
33
+ "@canopycanopycanopy/b-ber-shapes-directives": "2.0.2",
33
34
  "lodash": "^4.17.21",
34
35
  "lodash.find": "latest",
35
36
  "tar": "^6.1.11"
@@ -51,5 +52,5 @@
51
52
  "url": "https://maxwellsimmer.com"
52
53
  }
53
54
  ],
54
- "gitHead": "b4d9c563beb349a32c19e0f65447f7c7dbc8ea52"
55
+ "gitHead": "9b13185f21f602f8a2bf3a4cf503b1fd644d6432"
55
56
  }