@takeshape/util 8.16.0 → 8.20.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.
- package/es/common.js +4 -1
- package/es/draftjs-templates.js +148 -0
- package/es/draftjs.js +871 -0
- package/es/get-image-url.js +8 -0
- package/es/highlight-code.js +27 -0
- package/es/templates.js +97 -0
- package/lib/common.d.ts +3 -0
- package/lib/common.d.ts.map +1 -1
- package/lib/common.js +39 -0
- package/lib/draftjs-templates.d.ts +47 -0
- package/lib/draftjs-templates.d.ts.map +1 -0
- package/lib/draftjs-templates.js +168 -0
- package/lib/draftjs.d.ts +27 -0
- package/lib/draftjs.d.ts.map +1 -0
- package/lib/draftjs.js +901 -0
- package/lib/get-image-url.d.ts +5 -0
- package/lib/get-image-url.d.ts.map +1 -0
- package/lib/get-image-url.js +16 -0
- package/lib/highlight-code.d.ts +15 -0
- package/lib/highlight-code.d.ts.map +1 -0
- package/lib/highlight-code.js +53 -0
- package/lib/templates.d.ts +30 -0
- package/lib/templates.d.ts.map +1 -0
- package/lib/templates.js +121 -0
- package/package.json +12 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-image-url.d.ts","sourceRoot":"","sources":["../../src/get-image-url.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAA2B,WAAW,EAAC,MAAM,oBAAoB,CAAC;AAEnF,wBAAgB,WAAW,CACzB,IAAI,EAAE,SAAS,EACf,kBAAkB,EAAE;IAClB,IAAI,EAAE,MAAM,CAAC;CACd,EACD,YAAY,EAAE,MAAM,EACpB,MAAM,CAAC,EAAE,WAAW,GACnB,MAAM,CAER"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getImageUrl = getImageUrl;
|
|
7
|
+
|
|
8
|
+
var _routing = require("@takeshape/routing");
|
|
9
|
+
|
|
10
|
+
function getImageUrl(path, defaultImageConfig, imageBaseUrl, config) {
|
|
11
|
+
return (0, _routing.getImageUrl)(path, { ...defaultImageConfig,
|
|
12
|
+
...config
|
|
13
|
+
}, {
|
|
14
|
+
baseUrl: imageBaseUrl
|
|
15
|
+
});
|
|
16
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import 'prismjs/components/prism-javascript';
|
|
2
|
+
import 'prismjs/components/prism-markup';
|
|
3
|
+
import 'prismjs/components/prism-markup-templating';
|
|
4
|
+
import 'prismjs/components/prism-css';
|
|
5
|
+
import 'prismjs/components/prism-bash';
|
|
6
|
+
import 'prismjs/components/prism-django';
|
|
7
|
+
import 'prismjs/components/prism-twig';
|
|
8
|
+
import 'prismjs/components/prism-yaml';
|
|
9
|
+
import 'prismjs/components/prism-graphql';
|
|
10
|
+
import 'prismjs/components/prism-sass';
|
|
11
|
+
import 'prismjs/components/prism-scss';
|
|
12
|
+
import 'prismjs/components/prism-markdown';
|
|
13
|
+
import 'prismjs/components/prism-json';
|
|
14
|
+
export declare const highlightCode: (code: string, lang?: string | undefined) => string;
|
|
15
|
+
//# sourceMappingURL=highlight-code.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"highlight-code.d.ts","sourceRoot":"","sources":["../../src/highlight-code.ts"],"names":[],"mappings":"AAKA,OAAO,qCAAqC,CAAC;AAC7C,OAAO,iCAAiC,CAAC;AACzC,OAAO,4CAA4C,CAAC;AACpD,OAAO,8BAA8B,CAAC;AACtC,OAAO,+BAA+B,CAAC;AACvC,OAAO,iCAAiC,CAAC;AACzC,OAAO,+BAA+B,CAAC;AACvC,OAAO,+BAA+B,CAAC;AACvC,OAAO,kCAAkC,CAAC;AAC1C,OAAO,+BAA+B,CAAC;AACvC,OAAO,+BAA+B,CAAC;AACvC,OAAO,mCAAmC,CAAC;AAC3C,OAAO,+BAA+B,CAAC;AAGvC,eAAO,MAAM,aAAa,SAAU,MAAM,sCAOzC,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.highlightCode = void 0;
|
|
7
|
+
|
|
8
|
+
var _prismjs = _interopRequireDefault(require("prismjs"));
|
|
9
|
+
|
|
10
|
+
require("prismjs/components/prism-javascript");
|
|
11
|
+
|
|
12
|
+
require("prismjs/components/prism-markup");
|
|
13
|
+
|
|
14
|
+
require("prismjs/components/prism-markup-templating");
|
|
15
|
+
|
|
16
|
+
require("prismjs/components/prism-css");
|
|
17
|
+
|
|
18
|
+
require("prismjs/components/prism-bash");
|
|
19
|
+
|
|
20
|
+
require("prismjs/components/prism-django");
|
|
21
|
+
|
|
22
|
+
require("prismjs/components/prism-twig");
|
|
23
|
+
|
|
24
|
+
require("prismjs/components/prism-yaml");
|
|
25
|
+
|
|
26
|
+
require("prismjs/components/prism-graphql");
|
|
27
|
+
|
|
28
|
+
require("prismjs/components/prism-sass");
|
|
29
|
+
|
|
30
|
+
require("prismjs/components/prism-scss");
|
|
31
|
+
|
|
32
|
+
require("prismjs/components/prism-markdown");
|
|
33
|
+
|
|
34
|
+
require("prismjs/components/prism-json");
|
|
35
|
+
|
|
36
|
+
var _escape = _interopRequireDefault(require("lodash/escape"));
|
|
37
|
+
|
|
38
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
39
|
+
|
|
40
|
+
/*
|
|
41
|
+
* The intention is to move all this to the client package in the end, but right now it's here
|
|
42
|
+
* to be shared between the draftjs / mdx implementations, which span the client / server differently.
|
|
43
|
+
*/
|
|
44
|
+
const highlightCode = (code, lang) => {
|
|
45
|
+
if (lang) {
|
|
46
|
+
const syntax = _prismjs.default.languages[lang];
|
|
47
|
+
return _prismjs.default.highlight(code, syntax, lang);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return (0, _escape.default)(code);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
exports.highlightCode = highlightCode;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ImgixParams } from '@takeshape/routing';
|
|
2
|
+
import { MaybeContent } from './draftjs';
|
|
3
|
+
export declare function getApplyPrefix(prefix: string): (str: string) => string;
|
|
4
|
+
interface AttrsObj {
|
|
5
|
+
alt: string;
|
|
6
|
+
title: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function attrs(obj: AttrsObj): string;
|
|
9
|
+
export interface ImageTemplateData {
|
|
10
|
+
caption: string;
|
|
11
|
+
credit: string;
|
|
12
|
+
alignment: string;
|
|
13
|
+
size: string;
|
|
14
|
+
asset?: MaybeContent;
|
|
15
|
+
imageParams: ImgixParams;
|
|
16
|
+
link?: {
|
|
17
|
+
url: string;
|
|
18
|
+
external: boolean;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export declare function imageTemplate(applyPrefix: (str: string) => string, data: ImageTemplateData): string;
|
|
22
|
+
export declare function imageTemplateMdx(applyPrefix: (str: string) => string, data: Record<string, string>): string;
|
|
23
|
+
export declare function oembedTemplate(applyPrefix: (str: string) => string, data: Record<string, string>): string;
|
|
24
|
+
export declare function oembedTemplateMdx(applyPrefix: (str: string) => string, data: Record<string, string>): string;
|
|
25
|
+
export declare function codeTemplate(applyPrefix: (str: string) => string, data: {
|
|
26
|
+
text: string;
|
|
27
|
+
lang?: string;
|
|
28
|
+
}): string;
|
|
29
|
+
export {};
|
|
30
|
+
//# sourceMappingURL=templates.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../../src/templates.ts"],"names":[],"mappings":"AAOA,OAAO,EAAC,WAAW,EAAc,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAC,YAAY,EAAC,MAAM,WAAW,CAAC;AAEvC,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,CAA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"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.attrs = attrs;
|
|
7
|
+
exports.codeTemplate = codeTemplate;
|
|
8
|
+
exports.getApplyPrefix = getApplyPrefix;
|
|
9
|
+
exports.imageTemplate = imageTemplate;
|
|
10
|
+
exports.imageTemplateMdx = imageTemplateMdx;
|
|
11
|
+
exports.oembedTemplate = oembedTemplate;
|
|
12
|
+
exports.oembedTemplateMdx = oembedTemplateMdx;
|
|
13
|
+
|
|
14
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
15
|
+
|
|
16
|
+
var _highlightCode = require("./highlight-code");
|
|
17
|
+
|
|
18
|
+
var _escape = _interopRequireDefault(require("lodash/escape"));
|
|
19
|
+
|
|
20
|
+
var _routing = require("@takeshape/routing");
|
|
21
|
+
|
|
22
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
|
+
|
|
24
|
+
/*
|
|
25
|
+
* The intention is to move all this to the client package in the end, but right now it's here
|
|
26
|
+
* to be shared between the draftjs / mdx implementations, which span the client / server differently.
|
|
27
|
+
*/
|
|
28
|
+
function getApplyPrefix(prefix) {
|
|
29
|
+
return className => className ? prefix + className : '';
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function attrs(obj) {
|
|
33
|
+
const attrStrings = [];
|
|
34
|
+
const attrNames = Object.keys(obj);
|
|
35
|
+
attrNames.sort();
|
|
36
|
+
|
|
37
|
+
for (const attrName of attrNames) {
|
|
38
|
+
const value = obj[attrName];
|
|
39
|
+
|
|
40
|
+
if (value) {
|
|
41
|
+
attrStrings.push(`${attrName}="${(0, _escape.default)(value)}"`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return attrStrings.length ? ' ' + attrStrings.join(' ') : '';
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function imageTemplate(applyPrefix, data) {
|
|
49
|
+
var _data$link;
|
|
50
|
+
|
|
51
|
+
const {
|
|
52
|
+
caption,
|
|
53
|
+
credit,
|
|
54
|
+
alignment,
|
|
55
|
+
size,
|
|
56
|
+
asset,
|
|
57
|
+
imageParams
|
|
58
|
+
} = data;
|
|
59
|
+
|
|
60
|
+
if (!asset) {
|
|
61
|
+
return '';
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const imageUrl = (0, _routing.getImageUrl)(asset.path, imageParams);
|
|
65
|
+
let figCaption = '';
|
|
66
|
+
|
|
67
|
+
if (caption || credit) {
|
|
68
|
+
const htmlCaption = caption ? `<span class="${applyPrefix('caption')}">${caption}</span>` : '';
|
|
69
|
+
const htmlCredit = credit ? `<span class="${applyPrefix('credit')}">${credit}</span>` : '';
|
|
70
|
+
figCaption = `<figcaption>${htmlCaption} ${htmlCredit}</figcaption>`;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const classes = (0, _classnames.default)(applyPrefix(alignment), applyPrefix(size));
|
|
74
|
+
const classAttr = classes ? ` class="${classes}"` : '';
|
|
75
|
+
const imgAttrs = attrs({
|
|
76
|
+
alt: asset.description,
|
|
77
|
+
title: asset.title
|
|
78
|
+
});
|
|
79
|
+
let image = `<img${imgAttrs} src="${imageUrl}"/>`;
|
|
80
|
+
|
|
81
|
+
if ((_data$link = data.link) !== null && _data$link !== void 0 && _data$link.url) {
|
|
82
|
+
const target = data.link.external ? ' target="blank" rel="noopener noreferrer"' : '';
|
|
83
|
+
image = `<a href="${data.link.url}"${target}>${image}</a>`;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return `<figure${classAttr}>${image}${figCaption}</figure>`;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function renderMdx(tag, attributes, data, children) {
|
|
90
|
+
const tagWithAttributes = `${tag} ${attributes.map(attr => `${attr}="${(0, _escape.default)(data[attr])}"`).join(' ')}`;
|
|
91
|
+
|
|
92
|
+
if (children) {
|
|
93
|
+
return `<${tagWithAttributes}>
|
|
94
|
+
${children.replace(/[\n\r]+$/, '')}
|
|
95
|
+
</${tag}>`;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return `<${tagWithAttributes}/>`;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function imageTemplateMdx(applyPrefix, data) {
|
|
102
|
+
return renderMdx(applyPrefix('Image'), ['id', 'caption', 'credit', 'link', 'linkisexternal', 'alignment', 'size', 'src'], data);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function oembedTemplate(applyPrefix, data) {
|
|
106
|
+
return `<div class="${applyPrefix('oembed')}">${data.html}</div>`;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function oembedTemplateMdx(applyPrefix, data) {
|
|
110
|
+
return renderMdx(applyPrefix('Oembed'), ['url', 'author_name', 'author_url', 'width', 'height', 'type', 'cache_age', 'provider_name', 'version'], data, data.html);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function codeTemplate(applyPrefix, data) {
|
|
114
|
+
const {
|
|
115
|
+
text,
|
|
116
|
+
lang
|
|
117
|
+
} = data;
|
|
118
|
+
const code = (0, _highlightCode.highlightCode)(text, lang);
|
|
119
|
+
const langClass = lang ? ` class="${applyPrefix(`language-${lang}`)}"` : '';
|
|
120
|
+
return `<pre><code${langClass}>${code}</code></pre>`;
|
|
121
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@takeshape/util",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.20.2",
|
|
4
4
|
"description": "Shared utilities",
|
|
5
5
|
"homepage": "https://www.takeshape.io",
|
|
6
6
|
"repository": {
|
|
@@ -21,10 +21,20 @@
|
|
|
21
21
|
"es"
|
|
22
22
|
],
|
|
23
23
|
"dependencies": {
|
|
24
|
+
"@takeshape/routing": "8.20.2",
|
|
25
|
+
"@types/url-parse": "^1.4.4",
|
|
24
26
|
"aws-sdk": "^2.802.0",
|
|
27
|
+
"classnames": "^2.2.5",
|
|
28
|
+
"dom-serializer": "0.2.2",
|
|
29
|
+
"draft-js": "^0.11.7",
|
|
30
|
+
"htmlparser2": "^3.10.0",
|
|
25
31
|
"lodash": "^4.17.20",
|
|
32
|
+
"markdown-draft-js": "github:incompl/markdown-draft-js#deterministic-entity-keys-with-lib",
|
|
26
33
|
"mime-types": "^2.1.27",
|
|
27
|
-
"pify": "^5.0.0"
|
|
34
|
+
"pify": "^5.0.0",
|
|
35
|
+
"prismjs": "^1.25.0",
|
|
36
|
+
"shortid": "^2.2.16",
|
|
37
|
+
"url-parse": "^1.5.3"
|
|
28
38
|
},
|
|
29
39
|
"devDependencies": {
|
|
30
40
|
"@types/lodash": "^4.14.165",
|