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>
153 lines
5.0 KiB
JavaScript
153 lines
5.0 KiB
JavaScript
/*
|
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
Author Tobias Koppers @sokra
|
|
*/
|
|
|
|
"use strict";
|
|
|
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
|
const RuntimeModule = require("../RuntimeModule");
|
|
const Template = require("../Template");
|
|
const {
|
|
compareModulesByIdentifier,
|
|
compareStrings
|
|
} = require("../util/comparators");
|
|
|
|
/** @typedef {import("../Chunk")} Chunk */
|
|
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
|
/** @typedef {import("../Compilation")} Compilation */
|
|
/** @typedef {import("../CodeGenerationResults")} CodeGenerationResults */
|
|
|
|
class ShareRuntimeModule extends RuntimeModule {
|
|
constructor() {
|
|
super("sharing");
|
|
}
|
|
|
|
/**
|
|
* @returns {string | null} runtime code
|
|
*/
|
|
generate() {
|
|
const compilation = /** @type {Compilation} */ (this.compilation);
|
|
const {
|
|
runtimeTemplate,
|
|
outputOptions: { uniqueName, ignoreBrowserWarnings }
|
|
} = compilation;
|
|
const codeGenerationResults =
|
|
/** @type {CodeGenerationResults} */
|
|
(compilation.codeGenerationResults);
|
|
const chunkGraph = /** @type {ChunkGraph} */ (this.chunkGraph);
|
|
/** @type {Map<string, Map<number, Set<string>>>} */
|
|
const initCodePerScope = new Map();
|
|
for (const chunk of /** @type {Chunk} */ (
|
|
this.chunk
|
|
).getAllReferencedChunks()) {
|
|
const modules = chunkGraph.getOrderedChunkModulesIterableBySourceType(
|
|
chunk,
|
|
"share-init",
|
|
compareModulesByIdentifier
|
|
);
|
|
if (!modules) continue;
|
|
for (const m of modules) {
|
|
const data = codeGenerationResults.getData(
|
|
m,
|
|
chunk.runtime,
|
|
"share-init"
|
|
);
|
|
if (!data) continue;
|
|
for (const item of data) {
|
|
const { shareScope, initStage, init } = item;
|
|
let stages = initCodePerScope.get(shareScope);
|
|
if (stages === undefined) {
|
|
initCodePerScope.set(shareScope, (stages = new Map()));
|
|
}
|
|
let list = stages.get(initStage || 0);
|
|
if (list === undefined) {
|
|
stages.set(initStage || 0, (list = new Set()));
|
|
}
|
|
list.add(init);
|
|
}
|
|
}
|
|
}
|
|
return Template.asString([
|
|
`${RuntimeGlobals.shareScopeMap} = {};`,
|
|
"var initPromises = {};",
|
|
"var initTokens = {};",
|
|
`${RuntimeGlobals.initializeSharing} = ${runtimeTemplate.basicFunction(
|
|
"name, initScope",
|
|
[
|
|
"if(!initScope) initScope = [];",
|
|
"// handling circular init calls",
|
|
"var initToken = initTokens[name];",
|
|
"if(!initToken) initToken = initTokens[name] = {};",
|
|
"if(initScope.indexOf(initToken) >= 0) return;",
|
|
"initScope.push(initToken);",
|
|
"// only runs once",
|
|
"if(initPromises[name]) return initPromises[name];",
|
|
"// creates a new share scope if needed",
|
|
`if(!${RuntimeGlobals.hasOwnProperty}(${RuntimeGlobals.shareScopeMap}, name)) ${RuntimeGlobals.shareScopeMap}[name] = {};`,
|
|
"// runs all init snippets from all modules reachable",
|
|
`var scope = ${RuntimeGlobals.shareScopeMap}[name];`,
|
|
`var warn = ${
|
|
ignoreBrowserWarnings
|
|
? runtimeTemplate.basicFunction("", "")
|
|
: runtimeTemplate.basicFunction("msg", [
|
|
'if (typeof console !== "undefined" && console.warn) console.warn(msg);'
|
|
])
|
|
};`,
|
|
`var uniqueName = ${JSON.stringify(uniqueName || undefined)};`,
|
|
`var register = ${runtimeTemplate.basicFunction(
|
|
"name, version, factory, eager",
|
|
[
|
|
"var versions = scope[name] = scope[name] || {};",
|
|
"var activeVersion = versions[version];",
|
|
"if(!activeVersion || (!activeVersion.loaded && (!eager != !activeVersion.eager ? eager : uniqueName > activeVersion.from))) versions[version] = { get: factory, from: uniqueName, eager: !!eager };"
|
|
]
|
|
)};`,
|
|
`var initExternal = ${runtimeTemplate.basicFunction("id", [
|
|
`var handleError = ${runtimeTemplate.expressionFunction(
|
|
'warn("Initialization of sharing external failed: " + err)',
|
|
"err"
|
|
)};`,
|
|
"try {",
|
|
Template.indent([
|
|
`var module = ${RuntimeGlobals.require}(id);`,
|
|
"if(!module) return;",
|
|
`var initFn = ${runtimeTemplate.returningFunction(
|
|
`module && module.init && module.init(${RuntimeGlobals.shareScopeMap}[name], initScope)`,
|
|
"module"
|
|
)}`,
|
|
"if(module.then) return promises.push(module.then(initFn, handleError));",
|
|
"var initResult = initFn(module);",
|
|
"if(initResult && initResult.then) return promises.push(initResult['catch'](handleError));"
|
|
]),
|
|
"} catch(err) { handleError(err); }"
|
|
])}`,
|
|
"var promises = [];",
|
|
"switch(name) {",
|
|
...[...initCodePerScope]
|
|
.sort(([a], [b]) => compareStrings(a, b))
|
|
.map(([name, stages]) =>
|
|
Template.indent([
|
|
`case ${JSON.stringify(name)}: {`,
|
|
Template.indent(
|
|
[...stages]
|
|
.sort(([a], [b]) => a - b)
|
|
.map(([, initCode]) => Template.asString([...initCode]))
|
|
),
|
|
"}",
|
|
"break;"
|
|
])
|
|
),
|
|
"}",
|
|
"if(!promises.length) return initPromises[name] = 1;",
|
|
`return initPromises[name] = Promise.all(promises).then(${runtimeTemplate.returningFunction(
|
|
"initPromises[name] = 1"
|
|
)});`
|
|
]
|
|
)};`
|
|
]);
|
|
}
|
|
}
|
|
|
|
module.exports = ShareRuntimeModule;
|