@nascentdigital/funnel-core 4.4.13 → 4.4.14
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,9 +1,24 @@
|
|
|
1
1
|
export type BlockLayout = {
|
|
2
2
|
name: string;
|
|
3
3
|
root: BlockLayout.Root;
|
|
4
|
-
|
|
4
|
+
tight?: BlockLayout.Tight;
|
|
5
|
+
tightMobile?: BlockLayout.Tight;
|
|
6
|
+
tightDesktop?: BlockLayout.Tight;
|
|
5
7
|
};
|
|
6
8
|
export declare namespace BlockLayout {
|
|
9
|
+
type Tight = 'above' | 'below' | 'both' | 'none';
|
|
10
|
+
namespace Tight {
|
|
11
|
+
const values: ReadonlyArray<Tight>;
|
|
12
|
+
function parse(value: string, fallback?: Tight): Tight;
|
|
13
|
+
}
|
|
14
|
+
type Ratio = '1/1' | '1/2' | '1/3' | '2/1' | '3/1' | '2/3' | '3/2';
|
|
15
|
+
namespace Ratio {
|
|
16
|
+
const values: ReadonlyArray<Ratio>;
|
|
17
|
+
function parse(value: string, fallback?: Ratio): Ratio;
|
|
18
|
+
}
|
|
19
|
+
namespace FullBleed {
|
|
20
|
+
function parse(value: string, fallback?: boolean): boolean;
|
|
21
|
+
}
|
|
7
22
|
type Root = Row | Column | Stack;
|
|
8
23
|
type Container = Row | Row.Nested | Column | Column.Nested | Stack | Stack.Nested;
|
|
9
24
|
type Row = {
|
|
@@ -11,10 +26,14 @@ export declare namespace BlockLayout {
|
|
|
11
26
|
items: ReadonlyArray<Column.Nested | Stack.Nested | Panel>;
|
|
12
27
|
alignX?: Alignment;
|
|
13
28
|
alignY?: Alignment;
|
|
29
|
+
ratio?: Ratio;
|
|
30
|
+
ratioMobile?: Ratio;
|
|
31
|
+
ratioDesktop?: Ratio;
|
|
14
32
|
};
|
|
15
33
|
namespace Row {
|
|
16
34
|
type Nested = Omit<Row, 'items'> & {
|
|
17
35
|
items: ReadonlyArray<Panel>;
|
|
36
|
+
mobileOrder?: MobileOrder;
|
|
18
37
|
};
|
|
19
38
|
}
|
|
20
39
|
type Column = {
|
|
@@ -26,6 +45,7 @@ export declare namespace BlockLayout {
|
|
|
26
45
|
namespace Column {
|
|
27
46
|
type Nested = Omit<Column, 'items'> & {
|
|
28
47
|
items: ReadonlyArray<Panel>;
|
|
48
|
+
mobileOrder?: MobileOrder;
|
|
29
49
|
};
|
|
30
50
|
}
|
|
31
51
|
type Stack = {
|
|
@@ -37,6 +57,7 @@ export declare namespace BlockLayout {
|
|
|
37
57
|
namespace Stack {
|
|
38
58
|
type Nested = Omit<Stack, 'items'> & {
|
|
39
59
|
items: ReadonlyArray<Panel>;
|
|
60
|
+
mobileOrder?: MobileOrder;
|
|
40
61
|
};
|
|
41
62
|
}
|
|
42
63
|
type NestedItem = Row.Nested | Column.Nested | Stack.Nested | Panel;
|
|
@@ -46,18 +67,25 @@ export declare namespace BlockLayout {
|
|
|
46
67
|
type Base = {
|
|
47
68
|
key: Key;
|
|
48
69
|
mobileOrder?: MobileOrder;
|
|
49
|
-
alignX
|
|
50
|
-
alignY
|
|
51
|
-
size
|
|
70
|
+
alignX?: Alignment;
|
|
71
|
+
alignY?: Alignment;
|
|
72
|
+
size?: Size;
|
|
73
|
+
fullBleed?: boolean;
|
|
74
|
+
fullBleedMobile?: boolean;
|
|
75
|
+
fullBleedDesktop?: boolean;
|
|
52
76
|
};
|
|
53
77
|
}
|
|
54
78
|
type Message = Panel.Base & {
|
|
55
79
|
type: 'message';
|
|
56
|
-
textAlign
|
|
80
|
+
textAlign?: TextAlignment;
|
|
81
|
+
textAlignMobile?: TextAlignment;
|
|
82
|
+
textAlignDesktop?: TextAlignment;
|
|
57
83
|
};
|
|
58
84
|
type Visual = Panel.Base & {
|
|
59
85
|
type: 'visual';
|
|
60
86
|
aspectRatio: AspectRatio;
|
|
87
|
+
aspectRatioMobile?: AspectRatio;
|
|
88
|
+
aspectRatioDesktop?: AspectRatio;
|
|
61
89
|
};
|
|
62
90
|
type List = Panel.Base & {
|
|
63
91
|
type: 'list';
|
|
@@ -17,6 +17,71 @@ const errors_1 = require("../../errors");
|
|
|
17
17
|
// extension
|
|
18
18
|
var BlockLayout;
|
|
19
19
|
(function (BlockLayout) {
|
|
20
|
+
let Tight;
|
|
21
|
+
(function (Tight) {
|
|
22
|
+
// values
|
|
23
|
+
Tight.values = ['above', 'below', 'both', 'none'];
|
|
24
|
+
// helper
|
|
25
|
+
function parse(value, fallback) {
|
|
26
|
+
// return if it's a match
|
|
27
|
+
if (Tight.values.includes(value)) {
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
30
|
+
// or fallback if we have one
|
|
31
|
+
else if (fallback) {
|
|
32
|
+
return fallback;
|
|
33
|
+
}
|
|
34
|
+
// or throw
|
|
35
|
+
else {
|
|
36
|
+
throw new errors_1.ArgumentError(`Invalid BlockLayout.Tight "${value}"`, 'value');
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
Tight.parse = parse;
|
|
40
|
+
})(Tight = BlockLayout.Tight || (BlockLayout.Tight = {}));
|
|
41
|
+
let Ratio;
|
|
42
|
+
(function (Ratio) {
|
|
43
|
+
// values
|
|
44
|
+
Ratio.values = ['1/1', '1/2', '1/3', '2/1', '3/1', '2/3', '3/2'];
|
|
45
|
+
// helper
|
|
46
|
+
function parse(value, fallback) {
|
|
47
|
+
// return if it's a match
|
|
48
|
+
if (Ratio.values.includes(value)) {
|
|
49
|
+
return value;
|
|
50
|
+
}
|
|
51
|
+
// or fallback if we have one
|
|
52
|
+
else if (fallback) {
|
|
53
|
+
return fallback;
|
|
54
|
+
}
|
|
55
|
+
// or throw
|
|
56
|
+
else {
|
|
57
|
+
throw new errors_1.ArgumentError(`Invalid BlockLayout.Ratio "${value}"`, 'value');
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
Ratio.parse = parse;
|
|
61
|
+
})(Ratio = BlockLayout.Ratio || (BlockLayout.Ratio = {}));
|
|
62
|
+
let FullBleed;
|
|
63
|
+
(function (FullBleed) {
|
|
64
|
+
// helper
|
|
65
|
+
function parse(value, fallback) {
|
|
66
|
+
// return true if the string is 'true'
|
|
67
|
+
if (value === 'true') {
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
// return false if the string is 'false'
|
|
71
|
+
else if (value === 'false') {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
// or fallback if we have one
|
|
75
|
+
else if (fallback !== undefined) {
|
|
76
|
+
return fallback;
|
|
77
|
+
}
|
|
78
|
+
// or throw
|
|
79
|
+
else {
|
|
80
|
+
throw new errors_1.ArgumentError(`Invalid BlockLayout.FullBleed "${value}"`, 'value');
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
FullBleed.parse = parse;
|
|
84
|
+
})(FullBleed = BlockLayout.FullBleed || (BlockLayout.FullBleed = {}));
|
|
20
85
|
let List;
|
|
21
86
|
(function (List) {
|
|
22
87
|
let ItemType;
|
|
@@ -153,28 +218,32 @@ var BlockLayout;
|
|
|
153
218
|
// parse xml (not sure if this throws on error)
|
|
154
219
|
const blockJson = xmlParser.parse(xml);
|
|
155
220
|
// walk json to create block data
|
|
156
|
-
return
|
|
221
|
+
return parseBlock(blockJson[0]);
|
|
157
222
|
}
|
|
158
223
|
BlockLayout.parse = parse;
|
|
159
224
|
})(BlockLayout || (exports.BlockLayout = BlockLayout = {}));
|
|
160
225
|
// helpers
|
|
161
|
-
function
|
|
226
|
+
function parseBlock(json) {
|
|
162
227
|
// parse block
|
|
163
228
|
const block = ParsedElement.parse({ data: json, expectedTags: ['block'], expectedChildren: 1 });
|
|
229
|
+
const tight = BlockLayout.Tight.parse(block.attributes['tight'], 'none');
|
|
164
230
|
// return block
|
|
165
231
|
return {
|
|
166
232
|
name: block.attributes['name'],
|
|
233
|
+
tight,
|
|
234
|
+
tightMobile: BlockLayout.Tight.parse(block.attributes['tightMobile'], tight),
|
|
235
|
+
tightDesktop: BlockLayout.Tight.parse(block.attributes['tightDesktop'], tight),
|
|
167
236
|
root: parseRoot(ParsedElement.parse({ data: block.children[0], expectedTags: ['row', 'col', 'stack'] })),
|
|
168
|
-
fullbleed: block.attributes['fullbleed'] === 'true'
|
|
169
237
|
};
|
|
170
238
|
}
|
|
171
239
|
function parseRoot({ tag, attributes, children }) {
|
|
240
|
+
const ratio = BlockLayout.Ratio.parse(attributes['ratio'], '1/1');
|
|
172
241
|
// parse attributes
|
|
173
|
-
const
|
|
242
|
+
const _a = parseItemAttributes(attributes), { size } = _a, itemAttributes = __rest(_a, ["size"]);
|
|
174
243
|
// create root
|
|
175
244
|
switch (tag) {
|
|
176
245
|
case 'row':
|
|
177
|
-
return Object.assign(Object.assign({ type: 'row' }, itemAttributes), { items: children.map(data => parseNestedItem(ParsedElement.parse({
|
|
246
|
+
return Object.assign(Object.assign({ type: 'row' }, itemAttributes), { ratio, ratioMobile: BlockLayout.Ratio.parse(attributes['ratioMobile'], ratio), ratioDesktop: BlockLayout.Ratio.parse(attributes['ratioDesktop'], ratio), items: children.map(data => parseNestedItem(ParsedElement.parse({
|
|
178
247
|
data,
|
|
179
248
|
expectedTags: ParsedElement.tags.filter(t => t !== tag)
|
|
180
249
|
}))) });
|
|
@@ -195,9 +264,14 @@ function parseRoot({ tag, attributes, children }) {
|
|
|
195
264
|
function parseNestedItem({ tag, attributes, children }) {
|
|
196
265
|
// parse attributes
|
|
197
266
|
const _a = parseItemAttributes(attributes), { size } = _a, itemAttributes = __rest(_a, ["size"]);
|
|
267
|
+
const ratio = BlockLayout.Ratio.parse(attributes['ratio'], '1/1');
|
|
198
268
|
// create container
|
|
199
269
|
switch (tag) {
|
|
200
270
|
case 'row':
|
|
271
|
+
return Object.assign(Object.assign({ type: 'row' }, itemAttributes), { ratio, ratioMobile: BlockLayout.Ratio.parse(attributes['ratioMobile'], ratio), ratioDesktop: BlockLayout.Ratio.parse(attributes['ratioDesktop'], ratio), items: children.map(data => parsePanel(Object.assign({}, ParsedElement.parse({
|
|
272
|
+
data,
|
|
273
|
+
expectedTags: ParsedElement.tags.filter(t => t !== 'row' && t !== 'col')
|
|
274
|
+
})))) });
|
|
201
275
|
case 'col':
|
|
202
276
|
case 'stack':
|
|
203
277
|
return Object.assign(Object.assign({ type: tag === 'col' ? 'column' : tag }, itemAttributes), { items: children.map(data => parsePanel(Object.assign({}, ParsedElement.parse({
|
|
@@ -212,13 +286,24 @@ function parsePanel({ tag, attributes }) {
|
|
|
212
286
|
var _a;
|
|
213
287
|
const key = (_a = attributes['key']) !== null && _a !== void 0 ? _a : tag;
|
|
214
288
|
const itemAttributes = parseItemAttributes(attributes);
|
|
289
|
+
const textAlign = BlockLayout.TextAlignment.parse(attributes['textAlign'], 'left');
|
|
290
|
+
const aspectRatio = BlockLayout.AspectRatio.parse(attributes['aspect'], 'auto');
|
|
291
|
+
const fullBleed = BlockLayout.FullBleed.parse(attributes['fullBleed'], false);
|
|
292
|
+
const fullBleedMobile = BlockLayout.FullBleed.parse(attributes['fullBleedMobile'], fullBleed);
|
|
293
|
+
const fullBleedDesktop = BlockLayout.FullBleed.parse(attributes['fullBleedDesktop'], fullBleed);
|
|
215
294
|
switch (tag) {
|
|
216
295
|
case 'message':
|
|
217
|
-
return Object.assign(Object.assign({ type: 'message', key }, itemAttributes), { textAlign: BlockLayout.TextAlignment.parse(attributes['
|
|
296
|
+
return Object.assign(Object.assign({ type: 'message', key }, itemAttributes), { textAlign, textAlignMobile: BlockLayout.TextAlignment.parse(attributes['textAlignMobile'], textAlign), textAlignDesktop: BlockLayout.TextAlignment.parse(attributes['textAlignDesktop'], textAlign), fullBleed,
|
|
297
|
+
fullBleedMobile,
|
|
298
|
+
fullBleedDesktop });
|
|
218
299
|
case 'visual':
|
|
219
|
-
return Object.assign(Object.assign({ type: 'visual', key }, itemAttributes), { aspectRatio: BlockLayout.AspectRatio.parse(attributes['
|
|
300
|
+
return Object.assign(Object.assign({ type: 'visual', key }, itemAttributes), { aspectRatio, aspectRatioMobile: BlockLayout.AspectRatio.parse(attributes['aspectMobile'], aspectRatio), aspectRatioDesktop: BlockLayout.AspectRatio.parse(attributes['aspectDesktop'], aspectRatio), fullBleed,
|
|
301
|
+
fullBleedMobile,
|
|
302
|
+
fullBleedDesktop });
|
|
220
303
|
case 'list':
|
|
221
|
-
return Object.assign(Object.assign({ type: 'list', key }, itemAttributes), {
|
|
304
|
+
return Object.assign(Object.assign({ type: 'list', key }, itemAttributes), { fullBleed,
|
|
305
|
+
fullBleedMobile,
|
|
306
|
+
fullBleedDesktop, itemType: BlockLayout.List.ItemType.parse(attributes['itemType'], 'message+visual') });
|
|
222
307
|
default:
|
|
223
308
|
throw new errors_1.ArgumentError(`Invalid XML BlockLayout - encountered "${tag}" where instead of BlockLayout.Panel`);
|
|
224
309
|
}
|
|
@@ -226,9 +311,9 @@ function parsePanel({ tag, attributes }) {
|
|
|
226
311
|
function parseItemAttributes(attributes) {
|
|
227
312
|
return {
|
|
228
313
|
mobileOrder: BlockLayout.MobileOrder.parse(attributes['mobileOrder']),
|
|
229
|
-
size: BlockLayout.Size.parse(attributes['size'], 'full'),
|
|
230
314
|
alignX: BlockLayout.Alignment.parse(attributes['alignX'], 'start'),
|
|
231
|
-
alignY: BlockLayout.Alignment.parse(attributes['alignY'], 'start')
|
|
315
|
+
alignY: BlockLayout.Alignment.parse(attributes['alignY'], 'start'),
|
|
316
|
+
size: BlockLayout.Size.parse(attributes['size'], 'full'),
|
|
232
317
|
};
|
|
233
318
|
}
|
|
234
319
|
var ParsedElement;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nascentdigital/funnel-core",
|
|
3
|
-
"version": "4.4.
|
|
3
|
+
"version": "4.4.14",
|
|
4
4
|
"repository": {
|
|
5
5
|
"url": "git+https://github.com/nascentdigital/funnel.git",
|
|
6
6
|
"directory": "libs/core"
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
"jest-tsd": "^0.2.2",
|
|
64
64
|
"ts-jest": "^29.3.2"
|
|
65
65
|
},
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "242a9e0979c03d4037eb2462c5b01b2a095e8e8f"
|
|
67
67
|
}
|