Add semantic token highlighting for 'that' variable and comment file references in VS Code extension Add Phone_Text_Input and Currency_Input components with formatting utilities Implement client widgets, form standardization, and soft delete functionality Add modal scroll lock and update documentation Implement comprehensive modal system with form integration and validation Fix modal component instantiation using jQuery plugin API Implement modal system with responsive sizing, queuing, and validation support Implement form submission with validation, error handling, and loading states Implement country/state selectors with dynamic data loading and Bootstrap styling Revert Rsx::Route() highlighting in Blade/PHP files Target specific PHP scopes for Rsx::Route() highlighting in Blade Expand injection selector for Rsx::Route() highlighting Add custom syntax highlighting for Rsx::Route() and Rsx.Route() calls Update jqhtml packages to v2.2.165 Add bundle path validation for common mistakes (development mode only) Create Ajax_Select_Input widget and Rsx_Reference_Data controller Create Country_Select_Input widget with default country support Initialize Tom Select on Select_Input widgets Add Tom Select bundle for enhanced select dropdowns Implement ISO 3166 geographic data system for country/region selection Implement widget-based form system with disabled state support 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
173 lines
5.1 KiB
JavaScript
Executable File
173 lines
5.1 KiB
JavaScript
Executable File
/*
|
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
*/
|
|
|
|
"use strict";
|
|
|
|
const { SyncWaterfallHook } = require("tapable");
|
|
const Compilation = require("../Compilation");
|
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
|
const Template = require("../Template");
|
|
const HelperRuntimeModule = require("./HelperRuntimeModule");
|
|
|
|
/** @typedef {import("../Chunk")} Chunk */
|
|
|
|
/**
|
|
* @typedef {object} LoadScriptCompilationHooks
|
|
* @property {SyncWaterfallHook<[string, Chunk]>} createScript
|
|
*/
|
|
|
|
/** @type {WeakMap<Compilation, LoadScriptCompilationHooks>} */
|
|
const compilationHooksMap = new WeakMap();
|
|
|
|
class LoadScriptRuntimeModule extends HelperRuntimeModule {
|
|
/**
|
|
* @param {Compilation} compilation the compilation
|
|
* @returns {LoadScriptCompilationHooks} hooks
|
|
*/
|
|
static getCompilationHooks(compilation) {
|
|
if (!(compilation instanceof Compilation)) {
|
|
throw new TypeError(
|
|
"The 'compilation' argument must be an instance of Compilation"
|
|
);
|
|
}
|
|
let hooks = compilationHooksMap.get(compilation);
|
|
if (hooks === undefined) {
|
|
hooks = {
|
|
createScript: new SyncWaterfallHook(["source", "chunk"])
|
|
};
|
|
compilationHooksMap.set(compilation, hooks);
|
|
}
|
|
return hooks;
|
|
}
|
|
|
|
/**
|
|
* @param {boolean=} withCreateScriptUrl use create script url for trusted types
|
|
* @param {boolean=} withFetchPriority use `fetchPriority` attribute
|
|
*/
|
|
constructor(withCreateScriptUrl, withFetchPriority) {
|
|
super("load script");
|
|
this._withCreateScriptUrl = withCreateScriptUrl;
|
|
this._withFetchPriority = withFetchPriority;
|
|
}
|
|
|
|
/**
|
|
* @returns {string | null} runtime code
|
|
*/
|
|
generate() {
|
|
const compilation = /** @type {Compilation} */ (this.compilation);
|
|
const { runtimeTemplate, outputOptions } = compilation;
|
|
const {
|
|
scriptType,
|
|
chunkLoadTimeout: loadTimeout,
|
|
crossOriginLoading,
|
|
uniqueName,
|
|
charset
|
|
} = outputOptions;
|
|
const fn = RuntimeGlobals.loadScript;
|
|
|
|
const { createScript } =
|
|
LoadScriptRuntimeModule.getCompilationHooks(compilation);
|
|
|
|
const code = Template.asString([
|
|
"script = document.createElement('script');",
|
|
scriptType ? `script.type = ${JSON.stringify(scriptType)};` : "",
|
|
charset ? "script.charset = 'utf-8';" : "",
|
|
`if (${RuntimeGlobals.scriptNonce}) {`,
|
|
Template.indent(
|
|
`script.setAttribute("nonce", ${RuntimeGlobals.scriptNonce});`
|
|
),
|
|
"}",
|
|
uniqueName
|
|
? 'script.setAttribute("data-webpack", dataWebpackPrefix + key);'
|
|
: "",
|
|
this._withFetchPriority
|
|
? Template.asString([
|
|
"if(fetchPriority) {",
|
|
Template.indent(
|
|
'script.setAttribute("fetchpriority", fetchPriority);'
|
|
),
|
|
"}"
|
|
])
|
|
: "",
|
|
`script.src = ${
|
|
this._withCreateScriptUrl
|
|
? `${RuntimeGlobals.createScriptUrl}(url)`
|
|
: "url"
|
|
};`,
|
|
crossOriginLoading
|
|
? crossOriginLoading === "use-credentials"
|
|
? 'script.crossOrigin = "use-credentials";'
|
|
: Template.asString([
|
|
"if (script.src.indexOf(window.location.origin + '/') !== 0) {",
|
|
Template.indent(
|
|
`script.crossOrigin = ${JSON.stringify(crossOriginLoading)};`
|
|
),
|
|
"}"
|
|
])
|
|
: ""
|
|
]);
|
|
|
|
return Template.asString([
|
|
"var inProgress = {};",
|
|
uniqueName
|
|
? `var dataWebpackPrefix = ${JSON.stringify(`${uniqueName}:`)};`
|
|
: "// data-webpack is not used as build has no uniqueName",
|
|
"// loadScript function to load a script via script tag",
|
|
`${fn} = ${runtimeTemplate.basicFunction(
|
|
`url, done, key, chunkId${
|
|
this._withFetchPriority ? ", fetchPriority" : ""
|
|
}`,
|
|
[
|
|
"if(inProgress[url]) { inProgress[url].push(done); return; }",
|
|
"var script, needAttach;",
|
|
"if(key !== undefined) {",
|
|
Template.indent([
|
|
'var scripts = document.getElementsByTagName("script");',
|
|
"for(var i = 0; i < scripts.length; i++) {",
|
|
Template.indent([
|
|
"var s = scripts[i];",
|
|
`if(s.getAttribute("src") == url${
|
|
uniqueName
|
|
? ' || s.getAttribute("data-webpack") == dataWebpackPrefix + key'
|
|
: ""
|
|
}) { script = s; break; }`
|
|
]),
|
|
"}"
|
|
]),
|
|
"}",
|
|
"if(!script) {",
|
|
Template.indent([
|
|
"needAttach = true;",
|
|
createScript.call(code, /** @type {Chunk} */ (this.chunk))
|
|
]),
|
|
"}",
|
|
"inProgress[url] = [done];",
|
|
`var onScriptComplete = ${runtimeTemplate.basicFunction(
|
|
"prev, event",
|
|
Template.asString([
|
|
"// avoid mem leaks in IE.",
|
|
"script.onerror = script.onload = null;",
|
|
"clearTimeout(timeout);",
|
|
"var doneFns = inProgress[url];",
|
|
"delete inProgress[url];",
|
|
"script.parentNode && script.parentNode.removeChild(script);",
|
|
`doneFns && doneFns.forEach(${runtimeTemplate.returningFunction(
|
|
"fn(event)",
|
|
"fn"
|
|
)});`,
|
|
"if(prev) return prev(event);"
|
|
])
|
|
)}`,
|
|
`var timeout = setTimeout(onScriptComplete.bind(null, undefined, { type: 'timeout', target: script }), ${loadTimeout});`,
|
|
"script.onerror = onScriptComplete.bind(null, script.onerror);",
|
|
"script.onload = onScriptComplete.bind(null, script.onload);",
|
|
"needAttach && document.head.appendChild(script);"
|
|
]
|
|
)};`
|
|
]);
|
|
}
|
|
}
|
|
|
|
module.exports = LoadScriptRuntimeModule;
|