@arponascension/express-inertia 1.5.2 → 1.6.0

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/dist/index.mjs CHANGED
@@ -724,94 +724,6 @@ function requestIdMiddleware() {
724
724
  function generateRequestId() {
725
725
  return randomUUID();
726
726
  }
727
-
728
- // src/directives.ts
729
- var customDirectives = {};
730
- function escapeJsString(str) {
731
- return str.replace(/\\/g, "\\\\").replace(/'/g, "\\'").replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
732
- }
733
- function registerDirective(name, handler) {
734
- customDirectives[name] = handler;
735
- }
736
- function clearCustomDirectives() {
737
- for (const name of Object.keys(customDirectives)) {
738
- delete customDirectives[name];
739
- }
740
- }
741
- function compileBladeDirectives(templateSource, localDirectives) {
742
- let compiled = templateSource;
743
- compiled = compiled.replace(
744
- /<x-inertia(\s[^>]*)?\s*(\/|><\/x-inertia>)/gi,
745
- (_match, attrs) => {
746
- const idMatch = attrs?.match(/id=(?:"([^"]*)"|'([^']*)')/);
747
- const id = idMatch ? idMatch[1] || idMatch[2] : void 0;
748
- return id ? `<%- inertia('${escapeJsString(id)}') %>` : `<%- inertia() %>`;
749
- }
750
- );
751
- compiled = compiled.replace(
752
- /<x-inertia-(?:script|data)(\s[^>]*)?\s*(\/|><\/x-inertia-(?:script|data)>)/gi,
753
- (_match, attrs) => {
754
- const idMatch = attrs?.match(/id=(?:"([^"]*)"|'([^']*)')/);
755
- const id = idMatch ? idMatch[1] || idMatch[2] : void 0;
756
- return id ? `<%- inertiaScript('${escapeJsString(id)}') %>` : `<%- inertiaScript() %>`;
757
- }
758
- );
759
- compiled = compiled.replace(
760
- /<x-inertia-head\s*(?:\/>|><\/x-inertia-head>)|<x-inertiaHead\s*(?:\/>|><\/x-inertiaHead>)/gi,
761
- "<%- inertiaHead() %>"
762
- );
763
- compiled = compiled.replace(
764
- /<x-vite(\s[^>]*)?\s*(?:\/>|><\/x-vite>)/gi,
765
- (_match, attrs) => {
766
- const srcMatch = attrs?.match(/(?:src|entries)=(?:"([^"]*)"|'([^']*)')/);
767
- const val = srcMatch ? srcMatch[1] || srcMatch[2] : "";
768
- if (val.startsWith("[") && val.endsWith("]")) {
769
- return `<%- vite(${val}) %>`;
770
- }
771
- return `<%- vite('${escapeJsString(val)}') %>`;
772
- }
773
- );
774
- compiled = compiled.replace(
775
- /<x-vite-react-refresh\s*(?:\/>|><\/x-vite-react-refresh>)|<x-viteReactRefresh\s*(?:\/>|><\/x-viteReactRefresh>)/gi,
776
- "<%- viteReactRefresh() %>"
777
- );
778
- compiled = compiled.replace(/<x-csrf\s*(?:\/>|><\/x-csrf>)/gi, "<%- csrf() %>");
779
- compiled = compiled.replace(
780
- /<x-routes(\s[^>]*)?\s*(?:\/>|><\/x-routes>)/gi,
781
- (_match, attrs) => {
782
- const groupMatch = attrs?.match(/group=(?:"([^"]*)"|'([^']*)')/);
783
- const group = groupMatch ? groupMatch[1] || groupMatch[2] : void 0;
784
- return group ? `<%- routes('${escapeJsString(group)}') %>` : `<%- routes() %>`;
785
- }
786
- );
787
- compiled = compiled.replace(/@inertiaHead\b/g, "<%- inertiaHead() %>");
788
- compiled = compiled.replace(/@(inertiaScript|inertiaData)(\([^)]*\))?(?!\w)/g, (_match, _d, args) => {
789
- return args ? `<%- inertiaScript${args} %>` : `<%- inertiaScript() %>`;
790
- });
791
- compiled = compiled.replace(/@inertia(\([^)]*\))?(?!\w)/g, (_match, args) => {
792
- return args ? `<%- inertia${args} %>` : `<%- inertia() %>`;
793
- });
794
- compiled = compiled.replace(/@viteReactRefresh\b/g, "<%- viteReactRefresh() %>");
795
- compiled = compiled.replace(/@vite\(([^)]*(?:\([^)]*\)[^)]*)*)\)/g, (_match, args) => {
796
- return `<%- vite(${args.trim()}) %>`;
797
- });
798
- compiled = compiled.replace(/@csrf\b/g, "<%- csrf() %>");
799
- compiled = compiled.replace(/@routes(\([^)]*\))?(?!\w)/g, (_match, args) => {
800
- return args ? `<%- routes${args} %>` : `<%- routes() %>`;
801
- });
802
- compiled = compiled.replace(/@json\(([^)]*(?:\([^)]*\)[^)]*)*)\)/g, (_match, args) => {
803
- return `<%- json(${args.trim()}) %>`;
804
- });
805
- const allDirectives = { ...customDirectives, ...localDirectives || {} };
806
- for (const [name, handler] of Object.entries(allDirectives)) {
807
- const escapedName = name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
808
- const pattern = new RegExp(`@${escapedName}(\\([^)]*(?:\\([^)]*\\)[^)]*)*\\))?(?!\\w)`, "g");
809
- compiled = compiled.replace(pattern, (_match, args) => {
810
- return handler(args ? args.slice(1, -1).trim() : "", {});
811
- });
812
- }
813
- return compiled;
814
- }
815
727
  function globToRegExp(glob) {
816
728
  const normalized = glob.replace(/\\/g, "/");
817
729
  let source = "";
@@ -1197,7 +1109,7 @@ function createInertiaEngine(options) {
1197
1109
  const templateTimestamps = /* @__PURE__ */ new Map();
1198
1110
  engineCaches.add(templateCache);
1199
1111
  engineTimestamps.add(templateTimestamps);
1200
- return function inertiaBladeEngine(filePath, rawOptions, callback) {
1112
+ return function inertiaEjsEngine(filePath, rawOptions, callback) {
1201
1113
  try {
1202
1114
  const template = options?.templateSource;
1203
1115
  const hasTemplateSource = template !== void 0;
@@ -1220,7 +1132,7 @@ function createInertiaEngine(options) {
1220
1132
  }
1221
1133
  if (!compiledTemplate) {
1222
1134
  const templateSource = template !== void 0 ? template : fs.readFileSync(filePath, "utf-8");
1223
- const compiledSource = options?.compileTemplate ? options.compileTemplate(templateSource) : compileBladeDirectives(templateSource, options?.directives);
1135
+ const compiledSource = options?.compileTemplate ? options.compileTemplate(templateSource) : templateSource;
1224
1136
  compiledTemplate = ejs.compile(compiledSource, {
1225
1137
  filename: filePath,
1226
1138
  cache: false,
@@ -1389,6 +1301,6 @@ function createPrefetchHelper(viteHelper) {
1389
1301
  // src/index.ts
1390
1302
  var src_default = createInertia;
1391
1303
 
1392
- export { CircuitBreaker, DEFAULT_COMPONENT_NAME_PATTERN, DEFAULT_SECURITY_OPTIONS, PrefetchHelper, ViteHelper, always, calculateBackoff, clearCustomDirectives, clearEngineCache, compileBladeDirectives, createInertia, createInertiaEngine, createLogger, createPrefetchHelper, createViteHelper, src_default as default, defaultViteHelper, defer, escapeHtmlAttr, generateSriHash, getGlobalLogger, createInertia as inertia, inertiaEngine, inertiaVitePlugin, isAlways, isDeferred, isLazy, isMerge, isOptional, lazy, merge, optional, registerDirective, renderSSR, requestIdMiddleware, resetAllCircuitBreakers, resolveProps, safeStringify, sanitizeViewData, serializePage, setGlobalLogger, shouldRetry, validateComponentName };
1304
+ export { CircuitBreaker, DEFAULT_COMPONENT_NAME_PATTERN, DEFAULT_SECURITY_OPTIONS, PrefetchHelper, ViteHelper, always, calculateBackoff, clearEngineCache, createInertia, createInertiaEngine, createLogger, createPrefetchHelper, createViteHelper, src_default as default, defaultViteHelper, defer, escapeHtmlAttr, generateSriHash, getGlobalLogger, createInertia as inertia, inertiaEngine, inertiaVitePlugin, isAlways, isDeferred, isLazy, isMerge, isOptional, lazy, merge, optional, renderSSR, requestIdMiddleware, resetAllCircuitBreakers, resolveProps, safeStringify, sanitizeViewData, serializePage, setGlobalLogger, shouldRetry, validateComponentName };
1393
1305
  //# sourceMappingURL=index.mjs.map
1394
1306
  //# sourceMappingURL=index.mjs.map