Comparing version 6.0.0-3 to 6.0.0-4
@@ -1,2 +0,3 @@ | ||
export { j as Edge } from './index-a4452d69.js'; | ||
import { E as EdgeGlobals } from './main-454013ec.js'; | ||
export { a as Edge } from './main-454013ec.js'; | ||
import 'edge-parser'; | ||
@@ -6,1 +7,8 @@ import 'edge-lexer/types'; | ||
import 'edge-parser/types'; | ||
/** | ||
* Inbuilt globals | ||
*/ | ||
declare const edgeGlobals: EdgeGlobals; | ||
export { edgeGlobals }; |
@@ -1,6 +0,15 @@ | ||
var __defProp = Object.defineProperty; | ||
var __export = (target, all) => { | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
}; | ||
import { | ||
StringifiedObject, | ||
Template, | ||
__export, | ||
asyncEach, | ||
each, | ||
escape, | ||
htmlSafe, | ||
isNotSubsetOf, | ||
isSubsetOf, | ||
parseJsArg, | ||
stringifyAttributes, | ||
unallowedExpression | ||
} from "./chunk-KB3QJCMR.js"; | ||
@@ -275,194 +284,2 @@ // src/loader.ts | ||
import { expressions } from "edge-parser"; | ||
// src/utils.ts | ||
import classNames from "classnames"; | ||
import { EdgeError } from "edge-error"; | ||
import { find, html } from "property-information"; | ||
function definePropertyInformation(property, value) { | ||
html.normal[property] = property; | ||
html.property[property] = { | ||
attribute: property, | ||
boolean: true, | ||
property, | ||
space: "html", | ||
booleanish: false, | ||
commaOrSpaceSeparated: false, | ||
commaSeparated: false, | ||
spaceSeparated: false, | ||
number: false, | ||
overloadedBoolean: false, | ||
defined: false, | ||
mustUseProperty: false, | ||
...value | ||
}; | ||
} | ||
definePropertyInformation("x-cloak"); | ||
definePropertyInformation("x-ignore"); | ||
definePropertyInformation("x-transition:enterstart", { | ||
attribute: "x-transition:enter-start", | ||
property: "x-transition:enterStart", | ||
boolean: false, | ||
spaceSeparated: true, | ||
commaOrSpaceSeparated: true | ||
}); | ||
definePropertyInformation("x-transition:enterend", { | ||
attribute: "x-transition:enter-end", | ||
property: "x-transition:enterEnd", | ||
boolean: false, | ||
spaceSeparated: true, | ||
commaOrSpaceSeparated: true | ||
}); | ||
definePropertyInformation("x-transition:leavestart", { | ||
attribute: "x-transition:leave-start", | ||
property: "x-transition:leaveStart", | ||
boolean: false, | ||
spaceSeparated: true, | ||
commaOrSpaceSeparated: true | ||
}); | ||
definePropertyInformation("x-transition:leaveend", { | ||
attribute: "x-transition:leave-end", | ||
property: "x-transition:leaveEnd", | ||
boolean: false, | ||
spaceSeparated: true, | ||
commaOrSpaceSeparated: true | ||
}); | ||
var alpineNamespaces = { | ||
x: "x-", | ||
xOn: "x-on:", | ||
xBind: "x-bind:", | ||
xTransition: "x-transition:" | ||
}; | ||
function unallowedExpression(message, filename, loc) { | ||
throw new EdgeError(message, "E_UNALLOWED_EXPRESSION", { | ||
line: loc.line, | ||
col: loc.col, | ||
filename | ||
}); | ||
} | ||
function isSubsetOf(expression, expressions12, errorCallback) { | ||
if (!expressions12.includes(expression.type)) { | ||
errorCallback(); | ||
} | ||
} | ||
function isNotSubsetOf(expression, expressions12, errorCallback) { | ||
if (expressions12.includes(expression.type)) { | ||
errorCallback(); | ||
} | ||
} | ||
function parseJsArg(parser, token) { | ||
return parser.utils.transformAst( | ||
parser.utils.generateAST(token.properties.jsArg, token.loc, token.filename), | ||
token.filename, | ||
parser | ||
); | ||
} | ||
function each(collection, iteratee) { | ||
if (Array.isArray(collection)) { | ||
for (let [key, value] of collection.entries()) { | ||
iteratee(value, key); | ||
} | ||
return; | ||
} | ||
if (typeof collection === "string") { | ||
let index = 0; | ||
for (let value of collection) { | ||
iteratee(value, index++); | ||
} | ||
return; | ||
} | ||
if (collection && typeof collection === "object") { | ||
for (let [key, value] of Object.entries(collection)) { | ||
iteratee(value, key); | ||
} | ||
} | ||
} | ||
async function asyncEach(collection, iteratee) { | ||
if (Array.isArray(collection)) { | ||
for (let [key, value] of collection.entries()) { | ||
await iteratee(value, key); | ||
} | ||
return; | ||
} | ||
if (typeof collection === "string") { | ||
let index = 0; | ||
for (let value of collection) { | ||
await iteratee(value, index++); | ||
} | ||
return; | ||
} | ||
if (collection && typeof collection === "object") { | ||
for (let [key, value] of Object.entries(collection)) { | ||
await iteratee(value, key); | ||
} | ||
} | ||
} | ||
var StringifiedObject = class { | ||
#obj = ""; | ||
addSpread(key) { | ||
this.#obj += this.#obj.length ? `, ${key}` : `${key}`; | ||
} | ||
/** | ||
* Add key/value pair to the object. | ||
* | ||
* ```js | ||
* stringifiedObject.add('username', `'virk'`) | ||
* ``` | ||
*/ | ||
add(key, value, isComputed = false) { | ||
key = isComputed ? `[${key}]` : key; | ||
this.#obj += this.#obj.length ? `, ${key}: ${value}` : `${key}: ${value}`; | ||
} | ||
/** | ||
* Returns the object alike string back. | ||
* | ||
* ```js | ||
* stringifiedObject.flush() | ||
* | ||
* // returns | ||
* `{ username: 'virk' }` | ||
* ``` | ||
*/ | ||
flush() { | ||
const obj = `{ ${this.#obj} }`; | ||
this.#obj = ""; | ||
return obj; | ||
} | ||
}; | ||
function stringifyAttributes(props, namespace) { | ||
const attributes = Object.keys(props); | ||
if (attributes.length === 0) { | ||
return ""; | ||
} | ||
return attributes.reduce((result, key) => { | ||
let value = props[key]; | ||
key = namespace ? `${namespace}${key}` : key; | ||
if (!value) { | ||
return result; | ||
} | ||
if (alpineNamespaces[key] && typeof value === "object") { | ||
result = result.concat(stringifyAttributes(value, alpineNamespaces[key])); | ||
return result; | ||
} | ||
const propInfo = find(html, key); | ||
const attribute = propInfo.attribute; | ||
if (!propInfo || propInfo.space === "svg") { | ||
return result; | ||
} | ||
if (propInfo.boolean) { | ||
result.push(attribute); | ||
return result; | ||
} | ||
if (key === "class") { | ||
value = `"${classNames(value)}"`; | ||
} else if (Array.isArray(value)) { | ||
value = `"${value.join(propInfo.commaSeparated ? "," : " ")}"`; | ||
} else if (!propInfo.booleanish && !propInfo.number) { | ||
value = `"${String(value)}"`; | ||
} | ||
result.push(`${attribute}=${value}`); | ||
return result; | ||
}, []).join(" "); | ||
} | ||
// src/tags/if.ts | ||
var ifTag = { | ||
@@ -638,3 +455,3 @@ block: true, | ||
// src/tags/slot.ts | ||
import { EdgeError as EdgeError2 } from "edge-error"; | ||
import { EdgeError } from "edge-error"; | ||
var slotTag = { | ||
@@ -646,3 +463,3 @@ block: true, | ||
compile(_, __, token) { | ||
throw new EdgeError2( | ||
throw new EdgeError( | ||
"@slot tag must appear as top level tag inside the @component tag", | ||
@@ -901,3 +718,3 @@ "E_ORPHAN_SLOT_TAG", | ||
// src/tags/component.ts | ||
import { EdgeError as EdgeError3 } from "edge-error"; | ||
import { EdgeError as EdgeError2 } from "edge-error"; | ||
import * as lexerUtils2 from "edge-lexer/utils"; | ||
@@ -964,3 +781,3 @@ import { expressions as expressions10 } from "edge-parser"; | ||
if (parsed.expressions.length > 2) { | ||
throw new EdgeError3("maximum of 2 arguments are allowed for @slot tag", "E_MAX_ARGUMENTS", { | ||
throw new EdgeError2("maximum of 2 arguments are allowed for @slot tag", "E_MAX_ARGUMENTS", { | ||
line: parsed.loc.start.line, | ||
@@ -1078,3 +895,3 @@ col: parsed.loc.start.column, | ||
// src/tags/include_if.ts | ||
import { EdgeError as EdgeError4 } from "edge-error"; | ||
import { EdgeError as EdgeError3 } from "edge-error"; | ||
import { expressions as expressions11 } from "edge-parser"; | ||
@@ -1099,3 +916,3 @@ var includeIfTag = { | ||
if (parsed.expressions.length !== 2) { | ||
throw new EdgeError4("@includeIf expects a total of 2 arguments", "E_ARGUMENTS_MIS_MATCH", { | ||
throw new EdgeError3("@includeIf expects a total of 2 arguments", "E_ARGUMENTS_MIS_MATCH", { | ||
line: parsed.loc.start.line, | ||
@@ -1137,3 +954,3 @@ col: parsed.loc.start.column, | ||
// src/compiler.ts | ||
import { EdgeError as EdgeError5 } from "edge-error"; | ||
import { EdgeError as EdgeError4 } from "edge-error"; | ||
import * as lexerUtils3 from "edge-lexer/utils"; | ||
@@ -1246,3 +1063,3 @@ import { Parser as Parser4, EdgeBuffer as EdgeBuffer2, Stack } from "edge-parser"; | ||
const [line, col] = lexerUtils3.getLineAndColumn(node); | ||
throw new EdgeError5( | ||
throw new EdgeError4( | ||
'Template extending a layout can only use "@section" or "@set" tags as top level nodes', | ||
@@ -1410,306 +1227,5 @@ "E_UNALLOWED_EXPRESSION", | ||
// src/template.ts | ||
import he from "he"; | ||
import { EdgeError as EdgeError6 } from "edge-error"; | ||
import lodash6 from "@poppinss/utils/lodash"; | ||
import Macroable from "@poppinss/macroable"; | ||
// src/migrate/props.ts | ||
import lodash5 from "@poppinss/utils/lodash"; | ||
import stringifyAttributes2 from "stringify-attributes"; | ||
// src/component/props.ts | ||
import lodash4 from "@poppinss/utils/lodash"; | ||
var ComponentProps = class _ComponentProps { | ||
#values; | ||
constructor(values) { | ||
this.#values = values; | ||
} | ||
/** | ||
* Reference to props raw values | ||
*/ | ||
all() { | ||
return this.#values; | ||
} | ||
/** | ||
* Check if a key exists | ||
*/ | ||
has(key) { | ||
return lodash4.has(this.#values, key); | ||
} | ||
/** | ||
* Get key value | ||
*/ | ||
get(key, defaultValue) { | ||
return lodash4.get(this.#values, key, defaultValue); | ||
} | ||
/** | ||
* Returns a new props bag with only the mentioned keys | ||
*/ | ||
only(keys) { | ||
return new _ComponentProps(lodash4.pick(this.#values, keys)); | ||
} | ||
/** | ||
* Returns a new props bag with except the mentioned keys | ||
*/ | ||
except(keys) { | ||
return new _ComponentProps(lodash4.omit(this.#values, keys)); | ||
} | ||
/** | ||
* Define defaults for the props values. | ||
* | ||
* - All other attributes will be overwritten when defined in props | ||
* - Classes will be merged together. | ||
*/ | ||
defaults(values) { | ||
if (values.class && this.#values["class"]) { | ||
const classes = { ...values.class, ...this.#values.class }; | ||
return new _ComponentProps({ ...values, ...this.#values, class: classes }); | ||
} | ||
return new _ComponentProps({ ...values, ...this.#values }); | ||
} | ||
/** | ||
* Converts props to HTML attributes | ||
*/ | ||
toAttrs() { | ||
return htmlSafe(stringifyAttributes(this.#values)); | ||
} | ||
}; | ||
// src/migrate/props.ts | ||
var Props = class { | ||
/** | ||
* Use ".next" property to migrate to newer | ||
* api | ||
*/ | ||
next; | ||
constructor(props) { | ||
this[Symbol.for("options")] = { props }; | ||
Object.assign(this, props); | ||
this.next = new ComponentProps(props); | ||
} | ||
/** | ||
* Merges the className attribute with the class attribute | ||
*/ | ||
#mergeClassAttributes(props) { | ||
if (props.className) { | ||
if (!props.class) { | ||
props.class = []; | ||
} | ||
if (!Array.isArray(props.class)) { | ||
props.class = [props.class]; | ||
} | ||
props.class = props.class.concat(props.className); | ||
props.className = false; | ||
} | ||
return props; | ||
} | ||
/** | ||
* Find if a key exists inside the props | ||
*/ | ||
has(key) { | ||
const value = this.get(key); | ||
return value !== void 0 && value !== null; | ||
} | ||
/** | ||
* Get value for a given key | ||
*/ | ||
get(key, defaultValue) { | ||
return lodash5.get(this.all(), key, defaultValue); | ||
} | ||
/** | ||
* Returns all the props | ||
*/ | ||
all() { | ||
return this[Symbol.for("options")].props; | ||
} | ||
/** | ||
* Validate prop value | ||
*/ | ||
validate(key, validateFn) { | ||
const value = this.get(key); | ||
validateFn(key, value); | ||
} | ||
/** | ||
* Return values for only the given keys | ||
*/ | ||
only(keys) { | ||
return lodash5.pick(this.all(), keys); | ||
} | ||
/** | ||
* Return values except the given keys | ||
*/ | ||
except(keys) { | ||
return lodash5.omit(this.all(), keys); | ||
} | ||
/** | ||
* Serialize all props to a string of HTML attributes | ||
*/ | ||
serialize(mergeProps, prioritizeInline = true) { | ||
const attributes = prioritizeInline ? lodash5.merge({}, this.all(), mergeProps) : lodash5.merge({}, mergeProps, this.all()); | ||
return htmlSafe(stringifyAttributes2(this.#mergeClassAttributes(attributes))); | ||
} | ||
/** | ||
* Serialize only the given keys to a string of HTML attributes | ||
*/ | ||
serializeOnly(keys, mergeProps, prioritizeInline = true) { | ||
const attributes = prioritizeInline ? lodash5.merge({}, this.only(keys), mergeProps) : lodash5.merge({}, mergeProps, this.only(keys)); | ||
return htmlSafe(stringifyAttributes2(this.#mergeClassAttributes(attributes))); | ||
} | ||
/** | ||
* Serialize except the given keys to a string of HTML attributes | ||
*/ | ||
serializeExcept(keys, mergeProps, prioritizeInline = true) { | ||
const attributes = prioritizeInline ? lodash5.merge({}, this.except(keys), mergeProps) : lodash5.merge({}, mergeProps, this.except(keys)); | ||
return htmlSafe(stringifyAttributes2(this.#mergeClassAttributes(attributes))); | ||
} | ||
}; | ||
// src/template.ts | ||
var SafeValue = class { | ||
constructor(value) { | ||
this.value = value; | ||
} | ||
}; | ||
function escape(input) { | ||
return input instanceof SafeValue ? input.value : he.escape(String(input)); | ||
} | ||
function htmlSafe(value) { | ||
return new SafeValue(value); | ||
} | ||
var Template = class extends Macroable { | ||
#compiler; | ||
#processor; | ||
/** | ||
* The shared state is used to hold the globals and locals, | ||
* since it is shared with components too. | ||
*/ | ||
#sharedState; | ||
constructor(compiler, globals, locals, processor) { | ||
super(); | ||
this.#compiler = compiler; | ||
this.#processor = processor; | ||
this.#sharedState = compiler.compat ? lodash6.merge({}, globals, locals) : { | ||
...globals, | ||
...locals | ||
}; | ||
} | ||
/** | ||
* Trims top and bottom new lines from the content | ||
*/ | ||
#trimTopBottomNewLines(value) { | ||
return value.replace(/^\n|^\r\n/, "").replace(/\n$|\r\n$/, ""); | ||
} | ||
/** | ||
* Render a compiled template with state | ||
*/ | ||
#renderCompiled(compiledTemplate, state) { | ||
const templateState = { ...this.#sharedState, ...state }; | ||
const $context = {}; | ||
if (this.#compiler.async) { | ||
return compiledTemplate(this, templateState, $context).then((output2) => { | ||
output2 = this.#trimTopBottomNewLines(output2); | ||
return this.#processor.executeOutput({ output: output2, template: this, state: templateState }); | ||
}); | ||
} | ||
const output = this.#trimTopBottomNewLines(compiledTemplate(this, templateState, $context)); | ||
return this.#processor.executeOutput({ output, template: this, state: templateState }); | ||
} | ||
/** | ||
* Render a partial | ||
* | ||
* ```js | ||
* const partialFn = template.compilePartial('includes/user') | ||
* | ||
* // render and use output | ||
* partialFn(template, state, ctx) | ||
* ``` | ||
*/ | ||
compilePartial(templatePath, ...localVariables) { | ||
return this.#compiler.compile(templatePath, localVariables); | ||
} | ||
/** | ||
* Render a component | ||
* | ||
* ```js | ||
* const componentFn = template.compileComponent('components/button') | ||
* | ||
* // render and use output | ||
* componentFn(template, template.getComponentState(props, slots, caller), ctx) | ||
* ``` | ||
*/ | ||
compileComponent(templatePath) { | ||
return this.#compiler.compile(templatePath); | ||
} | ||
/** | ||
* Returns the isolated state for a given component | ||
*/ | ||
getComponentState(props, slots, caller) { | ||
return { | ||
...this.#sharedState, | ||
...props, | ||
$slots: slots, | ||
$caller: caller, | ||
$props: this.#compiler.compat ? new Props(props) : new ComponentProps(props) | ||
}; | ||
} | ||
/** | ||
* Render a template with it's state. | ||
* | ||
* ```js | ||
* template.render('welcome', { key: 'value' }) | ||
* ``` | ||
*/ | ||
render(template, state) { | ||
let compiledTemplate = this.#compiler.compile(template); | ||
return this.#renderCompiled(compiledTemplate, state); | ||
} | ||
/** | ||
* Render template from a raw string | ||
* | ||
* ```js | ||
* template.renderRaw('Hello {{ username }}', { username: 'virk' }) | ||
* ``` | ||
*/ | ||
renderRaw(contents, state, templatePath) { | ||
let compiledTemplate = this.#compiler.compileRaw(contents, templatePath); | ||
return this.#renderCompiled(compiledTemplate, state); | ||
} | ||
/** | ||
* Escapes the value to be HTML safe. Only strings are escaped | ||
* and rest all values will be returned as it is. | ||
*/ | ||
escape(input) { | ||
return escape(input); | ||
} | ||
/** | ||
* Raise an error | ||
*/ | ||
newError(errorMessage, filename, lineNumber, column) { | ||
throw new EdgeError6(errorMessage, "E_RUNTIME_EXCEPTION", { | ||
filename, | ||
line: lineNumber, | ||
col: column | ||
}); | ||
} | ||
/** | ||
* Rethrows the runtime exception by re-constructing the error message | ||
* to point back to the original filename | ||
*/ | ||
reThrow(error, filename, lineNumber) { | ||
if (error instanceof EdgeError6) { | ||
throw error; | ||
} | ||
const message = error.message.replace(/state\./, ""); | ||
throw new EdgeError6(message, "E_RUNTIME_EXCEPTION", { | ||
filename, | ||
line: lineNumber, | ||
col: 0 | ||
}); | ||
} | ||
}; | ||
// src/edge/globals.ts | ||
import stringify from "js-stringify"; | ||
import classNames2 from "classnames"; | ||
import classNames from "classnames"; | ||
import inspect from "@poppinss/inspect"; | ||
@@ -1759,3 +1275,3 @@ import string2 from "@poppinss/utils/string"; | ||
safe: htmlSafe, | ||
classNames: classNames2, | ||
classNames, | ||
attrs: (values) => { | ||
@@ -1862,3 +1378,3 @@ return htmlSafe(stringifyAttributes(values)); | ||
// src/edge/renderer.ts | ||
import lodash7 from "@poppinss/utils/lodash"; | ||
import lodash4 from "@poppinss/utils/lodash"; | ||
var EdgeRenderer = class { | ||
@@ -1884,3 +1400,3 @@ #compiler; | ||
share(data) { | ||
lodash7.merge(this.#locals, data); | ||
lodash4.merge(this.#locals, data); | ||
return this; | ||
@@ -2251,3 +1767,4 @@ } | ||
export { | ||
Edge | ||
Edge, | ||
edgeGlobals | ||
}; |
export * from 'edge-lexer/types'; | ||
import 'edge-parser'; | ||
export * from 'edge-parser/types'; | ||
export { d as CacheManagerContract, c as CompiledTemplate, e as CompilerOptions, C as ComponentsTree, i as EdgeBufferContract, f as EdgeGlobals, E as EdgeOptions, a as LoaderContract, L as LoaderTemplate, g as ParserContract, P as PluginFn, T as TagContract, h as TagTokenContract, b as TagsContract } from '../index-a4452d69.js'; | ||
export { AcornLoc, ClaimTagFn, MustacheTransformer, OnLineFn, ParserOptions, ParserTagDefinitionContract, TagTransformer } from 'edge-parser/types'; | ||
export { e as CacheManagerContract, d as CompiledTemplate, f as CompilerOptions, C as ComponentsTree, j as EdgeBufferContract, E as EdgeGlobals, g as EdgeOptions, b as LoaderContract, L as LoaderTemplate, h as ParserContract, P as PluginFn, T as TagContract, i as TagTokenContract, c as TagsContract } from '../main-454013ec.js'; | ||
import '@poppinss/macroable'; |
{ | ||
"name": "edge.js", | ||
"description": "Template engine", | ||
"version": "6.0.0-3", | ||
"version": "6.0.0-4", | ||
"engines": { | ||
@@ -16,4 +16,3 @@ "node": ">=18.16.0" | ||
"./types": "./build/src/types.js", | ||
"./plugins/migrate": "./build/src/migrate/plugin.js", | ||
"./globals": "./build/src/edge/globals.js" | ||
"./plugins/migrate": "./build/src/migrate/plugin.js" | ||
}, | ||
@@ -123,3 +122,4 @@ "scripts": { | ||
"./index.ts", | ||
"./src/types.ts" | ||
"./src/types.ts", | ||
"./src/migrate/plugin.ts" | ||
], | ||
@@ -126,0 +126,0 @@ "outDir": "./build", |
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
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
95564
11
3121