vue-sfc-customblocks.js 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const language_core_1 = require("@volar/language-core");
  4. const customBlockReg = /^(.*)\.customBlock_([^_]+)_(\d+)\.([^.]+)$/;
  5. const plugin = () => {
  6. return {
  7. version: 1,
  8. getEmbeddedFileNames(fileName, sfc) {
  9. const names = [];
  10. for (let i = 0; i < sfc.customBlocks.length; i++) {
  11. const customBlock = sfc.customBlocks[i];
  12. names.push(fileName + '.customBlock_' + customBlock.type + '_' + i + '.' + customBlock.lang);
  13. }
  14. return names;
  15. },
  16. resolveEmbeddedFile(_fileName, sfc, embeddedFile) {
  17. const match = embeddedFile.fileName.match(customBlockReg);
  18. if (match) {
  19. const index = parseInt(match[3]);
  20. const customBlock = sfc.customBlocks[index];
  21. embeddedFile.capabilities = language_core_1.FileCapabilities.full;
  22. embeddedFile.content.push([
  23. customBlock.content,
  24. customBlock.name,
  25. 0,
  26. language_core_1.FileRangeCapabilities.full,
  27. ]);
  28. }
  29. },
  30. };
  31. };
  32. exports.default = plugin;
  33. //# sourceMappingURL=vue-sfc-customblocks.js.map