@jsreport/jsreport-assets
Advanced tools
Comparing version 3.0.0-beta.1 to 3.0.0
@@ -0,0 +0,0 @@ const config = require('./jsreport.config') |
@@ -0,0 +0,0 @@ |
@@ -1,4 +0,2 @@ | ||
const Promise = require('bluebird') | ||
const fs = require('fs') | ||
const FS = Promise.promisifyAll(fs) | ||
const fs = require('fs/promises') | ||
const path = require('path') | ||
@@ -15,3 +13,3 @@ const minimatch = require('minimatch') | ||
async function readAsset (reporter, definition, id, name, encoding, req) { | ||
async function readAsset (reporter, definition, { id, name, encoding }, req) { | ||
const allowAssetsLinkedToFiles = definition.options.allowAssetsLinkedToFiles !== false | ||
@@ -109,3 +107,3 @@ | ||
return { | ||
content: resolveAssetLink(reporter, definition, req, name), | ||
content: resolveAssetLink(reporter, definition, req, { name }), | ||
filename: name | ||
@@ -140,3 +138,3 @@ } | ||
return { | ||
content: resolveAssetLink(reporter, definition, req, asset.link), | ||
content: resolveAssetLink(reporter, definition, req, { name: asset.link }), | ||
filename: name, | ||
@@ -148,3 +146,3 @@ entity: asset | ||
return { | ||
content: resolveAssetLink(reporter, definition, req, name), | ||
content: resolveAssetLink(reporter, definition, req, { name }), | ||
filename: name, | ||
@@ -188,4 +186,4 @@ entity: asset | ||
try { | ||
const content = await FS.readFileAsync(pathToLinkedFile) | ||
const stat = await FS.statAsync(pathToLinkedFile) | ||
const content = await fs.readFile(pathToLinkedFile) | ||
const stat = await fs.stat(pathToLinkedFile) | ||
@@ -229,3 +227,3 @@ return { | ||
function resolveAssetLink (reporter, definition, req, assetName) { | ||
function resolveAssetLink (reporter, definition, req, { name: assetName, module = false }) { | ||
if (definition.options.rootUrlForLinks) { | ||
@@ -240,4 +238,9 @@ return combineURLs(definition.options.rootUrlForLinks, 'assets/content/' + assetName) | ||
const baseUrl = req.context.http ? req.context.http.baseUrl : reporter.express.localhostUrl | ||
const url = baseUrl + '/assets/content/' + assetName | ||
return baseUrl + '/assets/content/' + assetName | ||
if (module) { | ||
return `${url}?module=true` | ||
} | ||
return url | ||
} | ||
@@ -244,0 +247,0 @@ |
@@ -1,4 +0,2 @@ | ||
const Promise = require('bluebird') | ||
const fs = require('fs') | ||
const FS = Promise.promisifyAll(fs) | ||
const fs = require('fs/promises') | ||
const path = require('path') | ||
@@ -55,7 +53,7 @@ const etag = require('etag') | ||
const assetLink = req.params.path + req.params['0'] | ||
responseAsset(() => readAsset(reporter, definition, null, assetLink, 'binary', req), req, res) | ||
responseAsset(() => readAsset(reporter, definition, { id: null, name: assetLink, encoding: 'binary' }, req), req, res) | ||
}) | ||
app.get('/assets/:id/content*', (req, res) => { | ||
responseAsset(() => readAsset(reporter, definition, req.params.id, null, 'binary', req), req, res) | ||
responseAsset(() => readAsset(reporter, definition, { id: req.params.id, name: null, encoding: 'binary' }, req), req, res) | ||
}) | ||
@@ -65,3 +63,3 @@ | ||
try { | ||
const asset = await readAsset(reporter, definition, req.params.id, null, 'binary', req) | ||
const asset = await readAsset(reporter, definition, { id: req.params.id, name: null, encoding: 'binary' }, req) | ||
@@ -152,3 +150,3 @@ req.options = req.options || {} | ||
try { | ||
await FS.writeFileAsync(linkPath(reporter, definition, update.$set.link), update.$set.content) | ||
await fs.writeFile(linkPath(reporter, definition, update.$set.link), update.$set.content) | ||
delete update.$set.forceUpdate | ||
@@ -155,0 +153,0 @@ delete update.$set.content |
@@ -1,3 +0,3 @@ | ||
const Promise = require('bluebird') | ||
const asyncReplace = Promise.promisify(require('async-replace')) | ||
const util = require('util') | ||
const asyncReplace = util.promisify(require('async-replace')) | ||
const { readAsset } = require('./assetsShared') | ||
@@ -53,3 +53,3 @@ const test = /{#asset ([^{}]{0,500})}/g | ||
readAsset(reporter, definition, null, assetName, encoding, req).then(function (res) { | ||
readAsset(reporter, definition, { id: null, name: assetName, encoding }, req).then(function (res) { | ||
replacedAssets.push(assetName) | ||
@@ -110,4 +110,4 @@ done(null, res.content) | ||
proxy.assets = { | ||
read: async (path, encoding) => { | ||
const r = await readAsset(reporter, definition, null, path, encoding, req) | ||
read: async (path, encoding, moduleMode = false) => { | ||
const r = await readAsset(reporter, definition, { id: null, name: path, encoding, moduleMode }, req) | ||
return r.content | ||
@@ -119,3 +119,3 @@ }, | ||
for (const a of sharedHelpersAssets) { | ||
const asset = await readAsset(reporter, definition, a._id, null, 'utf8', req) | ||
const asset = await readAsset(reporter, definition, { id: a._id, name: null, encoding: 'utf8' }, req) | ||
const functionNames = getTopLevelFunctions(asset.content.toString()) | ||
@@ -137,6 +137,6 @@ const userCode = `(() => { ${asset.content.toString()}; | ||
registerHelpers: async (path) => { | ||
const asset = await readAsset(reporter, definition, null, path, 'utf8', req) | ||
const asset = await readAsset(reporter, definition, { id: null, name: path, encoding: 'utf8' }, req) | ||
const functionNames = getTopLevelFunctions(asset.content.toString()) | ||
const userCode = `(() => { ${asset.content.toString()}; | ||
const userCode = `(async () => { ${asset.content.toString()}; | ||
__topLevelFunctions = {...__topLevelFunctions, ${functionNames.map(h => `"${h}": ${h}`).join(',')}} | ||
@@ -155,3 +155,3 @@ })()` | ||
require: async (path) => { | ||
const r = await readAsset(reporter, definition, null, path, 'utf8', req) | ||
const r = await readAsset(reporter, definition, { id: null, name: path, encoding: 'utf8' }, req) | ||
@@ -158,0 +158,0 @@ const userCode = [ |
{ | ||
"name": "@jsreport/jsreport-assets", | ||
"version": "3.0.0-beta.1", | ||
"version": "3.0.0", | ||
"description": "jsreport extension embedding static assets like fonts or helpers into the templates", | ||
@@ -25,15 +25,15 @@ "keywords": [ | ||
"build": "jsreport-studio-build", | ||
"lint": "standard", | ||
"prepublish": "jsreport-studio-build", | ||
"run": "npm run build && jsreport-studio-start --run-only", | ||
"start": "jsreport-studio-start", | ||
"lint": "standard", | ||
"test": "mocha test --timeout 5000 --exit && standard", | ||
"test": "mocha test --timeout 99999999 --exit && standard", | ||
"test:watch": "mocha test --watch" | ||
}, | ||
"dependencies": { | ||
"@jsreport/office": "3.0.0", | ||
"async-replace": "1.0.1", | ||
"bluebird": "3.5.4", | ||
"enhanced-resolve": "5.8.2", | ||
"etag": "1.8.1", | ||
"js-string-escape": "1.0.1", | ||
"@jsreport/office": "3.0.0-beta.1", | ||
"mime": "2.4.4", | ||
@@ -45,9 +45,9 @@ "minimatch": "3.0.4", | ||
"devDependencies": { | ||
"@jsreport/jsreport-core": "3.0.0", | ||
"@jsreport/jsreport-express": "3.0.0", | ||
"@jsreport/jsreport-handlebars": "3.0.0", | ||
"@jsreport/jsreport-jsrender": "3.0.0", | ||
"@jsreport/jsreport-scripts": "3.0.0-beta.1", | ||
"@jsreport/studio-dev": "3.0.0", | ||
"binary-extensions": "1.12.0", | ||
"@jsreport/jsreport-core": "3.0.0-beta.1", | ||
"@jsreport/jsreport-express": "3.0.0-beta.1", | ||
"@jsreport/jsreport-handlebars": "3.0.0-beta.1", | ||
"@jsreport/jsreport-jsrender": "3.0.0-beta.1", | ||
"@jsreport/jsreport-scripts": "3.0.0-beta.1", | ||
"@jsreport/studio-dev": "3.0.0-beta.1", | ||
"mocha": "8.2.1", | ||
@@ -60,3 +60,3 @@ "moment": "2.29.1", | ||
"engines": { | ||
"node": ">=8.9" | ||
"node": ">=16.11" | ||
}, | ||
@@ -75,2 +75,2 @@ "standard": { | ||
} | ||
} | ||
} |
@@ -0,0 +0,0 @@ # @jsreport/jsreport-assets |
@@ -5,3 +5,3 @@ /* eslint-disable no-unused-vars */ | ||
const jsreport = require('jsreport-proxy') | ||
const jsreport = require('jsreport-proxy') | ||
const assetVal = await jsreport.assets.read(path, encoding) | ||
@@ -8,0 +8,0 @@ return assetVal |
@@ -5,3 +5,2 @@ import React, { Component } from 'react' | ||
import superagent from 'superagent' | ||
import Promise from 'bluebird' | ||
import { CopyToClipboard } from 'react-copy-to-clipboard' | ||
@@ -114,3 +113,3 @@ import binaryExtensions from 'binary-extensions' | ||
if (this.isImage(entity)) { | ||
return `<img src="{#asset ${Studio.resolveEntityPath(entity)} @encoding=dataURI}" />` | ||
return `<img src="{{asset "${Studio.resolveEntityPath(entity)}" "dataURI"}}" />` | ||
} | ||
@@ -121,3 +120,3 @@ | ||
font-family: '${parts[0]}'; | ||
src: url({#asset ${Studio.resolveEntityPath(entity)} @encoding=dataURI}); | ||
src: url({{asset "${Studio.resolveEntityPath(entity)}" "dataURI"}}); | ||
format('${this.getFormat(extension)}'); | ||
@@ -128,6 +127,6 @@ }` | ||
if (this.isOfficeFile(entity)) { | ||
return `{#asset ${Studio.resolveEntityPath(entity)} @encoding=base64}` | ||
return `{{asset "${Studio.resolveEntityPath(entity)}" "base64"}}` | ||
} | ||
return `{#asset ${Studio.resolveEntityPath(entity)} @encoding=utf8}` | ||
return `{{asset "${Studio.resolveEntityPath(entity)}"}}` | ||
} | ||
@@ -268,3 +267,3 @@ | ||
<CopyToClipboard text={embeddingCode}> | ||
<a className='button confirmation' title='Coppy the embedding code to clipboard'> | ||
<a className='button confirmation' title='Copy the embedding code to clipboard'> | ||
<i className='fa fa-clipboard' /> | ||
@@ -271,0 +270,0 @@ </a> |
@@ -0,0 +0,0 @@ import React, { Component } from 'react' |
@@ -34,2 +34,4 @@ import React, { Component } from 'react' | ||
const targetAsset = e.target.targetAsset | ||
const activateNewTab = e.target.activateNewTab | ||
const onNewEntityCallback = e.target.onNewEntityCallback | ||
const uploadCallback = e.target.uploadCallback | ||
@@ -70,3 +72,7 @@ | ||
Studio.addExistingEntity(response) | ||
Studio.openTab(Object.assign({}, response)) | ||
Studio.openTab(Object.assign({}, response), activateNewTab) | ||
if (onNewEntityCallback) { | ||
onNewEntityCallback(response) | ||
} | ||
} | ||
@@ -116,2 +122,8 @@ | ||
if (opts.activateNewTab != null) { | ||
this.inputFileRef.current.activateNewTab = opts.activateNewTab | ||
} else { | ||
delete this.inputFileRef.current.activateNewTab | ||
} | ||
if (defaults) { | ||
@@ -132,2 +144,8 @@ this.inputFileRef.current.assetDefaults = defaults | ||
if (opts.onNewEntityCallback) { | ||
this.inputFileRef.current.onNewEntityCallback = opts.onNewEntityCallback | ||
} else { | ||
delete this.inputFileRef.current.onNewEntityCallback | ||
} | ||
if (opts.uploadCallback) { | ||
@@ -134,0 +152,0 @@ this.inputFileRef.current.uploadCallback = opts.uploadCallback |
@@ -16,2 +16,3 @@ import AssetEditor from './AssetEditor.js' | ||
Studio.sharedComponents.NewAssetModal = NewAssetModal | ||
Studio.addEditorComponent('assets', AssetEditor) | ||
@@ -18,0 +19,0 @@ |
@@ -55,3 +55,8 @@ import React, { Component } from 'react' | ||
Studio.addExistingEntity(response) | ||
Studio.openTab(response) | ||
Studio.openTab(response, this.props.options.activateNewTab) | ||
if (this.props.options.onNewEntity) { | ||
this.props.options.onNewEntity(response) | ||
} | ||
this.props.close() | ||
@@ -118,3 +123,9 @@ } catch (e) { | ||
className='button confirmation' | ||
onClick={() => { this.props.close(); AssetUploadButton.OpenUploadNew(this.props.options.defaults) }} | ||
onClick={() => { | ||
this.props.close() | ||
AssetUploadButton.OpenUploadNew(this.props.options.defaults, { | ||
activateNewTab: this.props.options.activateNewTab, | ||
onNewEntityCallback: this.props.options.onNewEntity | ||
}) | ||
}} | ||
>Upload | ||
@@ -121,0 +132,0 @@ </button> |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
3137
0
204231
19
1
+ Addedenhanced-resolve@5.8.2
+ Added@jsreport/office@3.0.0(transitive)
+ Addedaxios@0.23.0(transitive)
+ Addedenhanced-resolve@5.8.2(transitive)
+ Addedtapable@2.2.1(transitive)
- Removedbluebird@3.5.4
- Removed@jsreport/office@3.0.0-beta.1(transitive)
- Removedaxios@0.21.1(transitive)
- Removedbluebird@3.5.4(transitive)
Updated@jsreport/office@3.0.0