Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c085eef441 | |||
| b4f84513a6 |
@@ -66,9 +66,6 @@ The `config` object is an object with some of the following keys:
|
||||
needs a template. If undefined is returned, owl looks into the app templates.
|
||||
- **`warnIfNoStaticProps (boolean, default=false)`**: if true, Owl will log a warning
|
||||
whenever it encounters a component that does not provide a [static props description](props.md#props-validation).
|
||||
- **`customDirectives (object)`**: if given, the corresponding function on the object will be called
|
||||
on the template custom directives: `t-custom-*` (see [Custom Directives](templates.md#custom-directives)).
|
||||
- **`globalValues (object)`**: Global object of elements available at compilations.
|
||||
|
||||
## `mount` helper
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
- [Sub Templates](#sub-templates)
|
||||
- [Dynamic Sub Templates](#dynamic-sub-templates)
|
||||
- [Debugging](#debugging)
|
||||
- [Custom Directives](#custom-directives)
|
||||
- [Fragments](#fragments)
|
||||
- [Inline templates](#inline-templates)
|
||||
- [Rendering svg](#rendering-svg)
|
||||
@@ -81,7 +80,6 @@ needs. Here is a list of all Owl specific directives:
|
||||
| `t-slot`, `t-set-slot`, `t-slot-scope` | [Rendering a slot](slots.md) |
|
||||
| `t-model` | [Form input bindings](input_bindings.md) |
|
||||
| `t-tag` | [Rendering nodes with dynamic tag name](#dynamic-tag-names) |
|
||||
| `t-custom-*` | [Rendering nodes with custom directives](#custom-directives) |
|
||||
|
||||
## QWeb Template Reference
|
||||
|
||||
@@ -590,35 +588,6 @@ will stop execution if the browser dev tools are open.
|
||||
|
||||
will print 42 to the console.
|
||||
|
||||
### Custom Directives
|
||||
|
||||
Owl 2 supports the declaration of custom directives. To use them, an Object of functions needs to be configured on the owl APP:
|
||||
|
||||
```js
|
||||
new App(..., {
|
||||
customDirectives: {
|
||||
test_directive: function (el, value) {
|
||||
el.setAttribute("t-on-click", value);
|
||||
}
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
The functions will be called when a custom directive with the name of the
|
||||
function is found. The original element will be replaced with the one
|
||||
modified by the function.
|
||||
This :
|
||||
|
||||
```xml
|
||||
<div t-custom-test_directive="click" />
|
||||
```
|
||||
|
||||
will be replaced by :
|
||||
|
||||
```xml
|
||||
<div t-on-click="value"/>
|
||||
```
|
||||
|
||||
## Fragments
|
||||
|
||||
Owl 2 supports templates with an arbitrary number of root elements, or even just
|
||||
|
||||
@@ -82,22 +82,6 @@ in the sources tab as well.
|
||||
|
||||
<img src="screenshots/function_menu.png"/>
|
||||
|
||||
Using the right-click context menu on a property also allows to observe variables. Observed variables will
|
||||
be sent to a dedicated section of the details window and their value will be refreshed every 200ms. These
|
||||
variables are only shown when they are found and their access path will be kept in memory inside the
|
||||
browser so that it will always persist until the user decides to stop observing the variable. As in the
|
||||
browser's devtools, observed objects are displayed in reduced form and cannot be interacted with. It is
|
||||
still possible to send them to the console or remove them from the list using right-click.
|
||||
|
||||
<img src="screenshots/observe_variables.png"/>
|
||||
|
||||
The last section of the details window is filled with the component's lifecycle hooks. Using right click on
|
||||
them allows to place breakpoints inside the hook (either on its instance or class, hooks like mounted and
|
||||
willStart cannot have instance-based breakpoints because they will never trigger). Conditions in conditional
|
||||
breakpoints will be evaluated in the context of the component's definition.
|
||||
|
||||
<img src="screenshots/hooks.png"/>
|
||||
|
||||
There are several icons available to perform several of the actions described before in the components
|
||||
tree context menu and all these actions are also available by opening the menu by right-clicking on the
|
||||
component's name. Using the left click on the component's name will focus it in the components tree.
|
||||
|
||||
|
Before Width: | Height: | Size: 314 KiB After Width: | Height: | Size: 545 KiB |
|
Before Width: | Height: | Size: 193 KiB After Width: | Height: | Size: 387 KiB |
|
Before Width: | Height: | Size: 45 KiB After Width: | Height: | Size: 72 KiB |
|
Before Width: | Height: | Size: 188 KiB After Width: | Height: | Size: 320 KiB |
|
Before Width: | Height: | Size: 28 KiB |
|
Before Width: | Height: | Size: 172 KiB After Width: | Height: | Size: 206 KiB |
|
Before Width: | Height: | Size: 200 KiB After Width: | Height: | Size: 329 KiB |
|
Before Width: | Height: | Size: 74 KiB After Width: | Height: | Size: 166 KiB |
|
Before Width: | Height: | Size: 118 KiB |
|
Before Width: | Height: | Size: 346 KiB After Width: | Height: | Size: 536 KiB |
|
Before Width: | Height: | Size: 93 KiB After Width: | Height: | Size: 177 KiB |
@@ -1625,13 +1625,6 @@ function makeRootFiber(node) {
|
||||
fibersInError.delete(current);
|
||||
fibersInError.delete(root);
|
||||
current.appliedToDom = false;
|
||||
if (current instanceof RootFiber) {
|
||||
// it is possible that this fiber is a fiber that crashed while being
|
||||
// mounted, so the mounted list is possibly corrupted. We restore it to
|
||||
// its normal initial state (which is empty list or a list with a mount
|
||||
// fiber.
|
||||
current.mounted = current instanceof MountFiber ? [current] : [];
|
||||
}
|
||||
}
|
||||
return current;
|
||||
}
|
||||
@@ -1748,7 +1741,6 @@ class RootFiber extends Fiber {
|
||||
const node = this.node;
|
||||
this.locked = true;
|
||||
let current = undefined;
|
||||
let mountedFibers = this.mounted;
|
||||
try {
|
||||
// Step 1: calling all willPatch lifecycle hooks
|
||||
for (current of this.willPatch) {
|
||||
@@ -1768,6 +1760,7 @@ class RootFiber extends Fiber {
|
||||
node._patch();
|
||||
this.locked = false;
|
||||
// Step 4: calling all mounted lifecycle hooks
|
||||
let mountedFibers = this.mounted;
|
||||
while ((current = mountedFibers.pop())) {
|
||||
current = current;
|
||||
if (current.appliedToDom) {
|
||||
@@ -1788,15 +1781,6 @@ class RootFiber extends Fiber {
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
// if mountedFibers is not empty, this means that a crash occured while
|
||||
// calling the mounted hooks of some component. So, there may still be
|
||||
// some component that have been mounted, but for which the mounted hooks
|
||||
// have not been called. Here, we remove the willUnmount hooks for these
|
||||
// specific component to prevent a worse situation (willUnmount being
|
||||
// called even though mounted has not been called)
|
||||
for (let fiber of mountedFibers) {
|
||||
fiber.node.willUnmount = [];
|
||||
}
|
||||
this.locked = false;
|
||||
node.app.handleError({ fiber: current || this, error: e });
|
||||
}
|
||||
@@ -2286,12 +2270,6 @@ function collectionsProxyHandler(target, callback, targetRawType) {
|
||||
}
|
||||
|
||||
let currentNode = null;
|
||||
function saveCurrent() {
|
||||
let n = currentNode;
|
||||
return () => {
|
||||
currentNode = n;
|
||||
};
|
||||
}
|
||||
function getCurrent() {
|
||||
if (!currentNode) {
|
||||
throw new OwlError("No active component (a hook function should only be called in 'setup')");
|
||||
@@ -3243,9 +3221,6 @@ class TemplateSet {
|
||||
}
|
||||
}
|
||||
this.getRawTemplate = config.getTemplate;
|
||||
this.customDirectives = config.customDirectives || {};
|
||||
this.runtimeUtils = { ...helpers, __globals__: config.globalValues || {} };
|
||||
this.hasGlobalValues = Boolean(config.globalValues && Object.keys(config.globalValues).length);
|
||||
}
|
||||
static registerTemplate(name, fn) {
|
||||
globalTemplates[name] = fn;
|
||||
@@ -3302,7 +3277,7 @@ class TemplateSet {
|
||||
this.templates[name] = function (context, parent) {
|
||||
return templates[name].call(this, context, parent);
|
||||
};
|
||||
const template = templateFn(this, bdom, this.runtimeUtils);
|
||||
const template = templateFn(this, bdom, helpers);
|
||||
this.templates[name] = template;
|
||||
}
|
||||
return this.templates[name];
|
||||
@@ -3353,7 +3328,7 @@ TemplateSet.registerTemplate("__portal__", portalTemplate);
|
||||
//------------------------------------------------------------------------------
|
||||
// Misc types, constants and helpers
|
||||
//------------------------------------------------------------------------------
|
||||
const RESERVED_WORDS = "true,false,NaN,null,undefined,debugger,console,window,in,instanceof,new,function,return,eval,void,Math,RegExp,Array,Object,Date,__globals__".split(",");
|
||||
const RESERVED_WORDS = "true,false,NaN,null,undefined,debugger,console,window,in,instanceof,new,function,return,eval,void,Math,RegExp,Array,Object,Date".split(",");
|
||||
const WORD_REPLACEMENT = Object.assign(Object.create(null), {
|
||||
and: "&&",
|
||||
or: "||",
|
||||
@@ -3825,9 +3800,6 @@ class CodeGenerator {
|
||||
this.dev = options.dev || false;
|
||||
this.ast = ast;
|
||||
this.templateName = options.name;
|
||||
if (options.hasGlobalValues) {
|
||||
this.helpers.add("__globals__");
|
||||
}
|
||||
}
|
||||
generateCode() {
|
||||
const ast = this.ast;
|
||||
@@ -4644,7 +4616,7 @@ class CodeGenerator {
|
||||
case "translate":
|
||||
break;
|
||||
default:
|
||||
throw new OwlError(`Invalid prop suffix: ${suffix}`);
|
||||
throw new OwlError("Invalid prop suffix");
|
||||
}
|
||||
}
|
||||
name = /^[a-z_]+$/i.test(name) ? name : `'${name}'`;
|
||||
@@ -4866,33 +4838,29 @@ class CodeGenerator {
|
||||
// Parser
|
||||
// -----------------------------------------------------------------------------
|
||||
const cache = new WeakMap();
|
||||
function parse(xml, customDir) {
|
||||
const ctx = {
|
||||
inPreTag: false,
|
||||
customDirectives: customDir,
|
||||
};
|
||||
function parse(xml) {
|
||||
if (typeof xml === "string") {
|
||||
const elem = parseXML(`<t>${xml}</t>`).firstChild;
|
||||
return _parse(elem, ctx);
|
||||
return _parse(elem);
|
||||
}
|
||||
let ast = cache.get(xml);
|
||||
if (!ast) {
|
||||
// we clone here the xml to prevent modifying it in place
|
||||
ast = _parse(xml.cloneNode(true), ctx);
|
||||
ast = _parse(xml.cloneNode(true));
|
||||
cache.set(xml, ast);
|
||||
}
|
||||
return ast;
|
||||
}
|
||||
function _parse(xml, ctx) {
|
||||
function _parse(xml) {
|
||||
normalizeXML(xml);
|
||||
const ctx = { inPreTag: false };
|
||||
return parseNode(xml, ctx) || { type: 0 /* Text */, value: "" };
|
||||
}
|
||||
function parseNode(node, ctx) {
|
||||
if (!(node instanceof Element)) {
|
||||
return parseTextCommentNode(node, ctx);
|
||||
}
|
||||
return (parseTCustom(node, ctx) ||
|
||||
parseTDebugLog(node, ctx) ||
|
||||
return (parseTDebugLog(node, ctx) ||
|
||||
parseTForEach(node, ctx) ||
|
||||
parseTIf(node, ctx) ||
|
||||
parseTPortal(node, ctx) ||
|
||||
@@ -4934,35 +4902,6 @@ function parseTextCommentNode(node, ctx) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
function parseTCustom(node, ctx) {
|
||||
if (!ctx.customDirectives) {
|
||||
return null;
|
||||
}
|
||||
const nodeAttrsNames = node.getAttributeNames();
|
||||
for (let attr of nodeAttrsNames) {
|
||||
if (attr === "t-custom" || attr === "t-custom-") {
|
||||
throw new OwlError("Missing custom directive name with t-custom directive");
|
||||
}
|
||||
if (attr.startsWith("t-custom-")) {
|
||||
const directiveName = attr.split(".")[0].slice(9);
|
||||
const customDirective = ctx.customDirectives[directiveName];
|
||||
if (!customDirective) {
|
||||
throw new OwlError(`Custom directive "${directiveName}" is not defined`);
|
||||
}
|
||||
const value = node.getAttribute(attr);
|
||||
const modifiers = attr.split(".").slice(1);
|
||||
node.removeAttribute(attr);
|
||||
try {
|
||||
customDirective(node, value, modifiers);
|
||||
}
|
||||
catch (error) {
|
||||
throw new OwlError(`Custom directive "${directiveName}" throw the following error: ${error}`);
|
||||
}
|
||||
return parseNode(node, ctx);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
// debugging
|
||||
// -----------------------------------------------------------------------------
|
||||
@@ -5594,11 +5533,9 @@ function normalizeXML(el) {
|
||||
normalizeTEscTOut(el);
|
||||
}
|
||||
|
||||
function compile(template, options = {
|
||||
hasGlobalValues: false,
|
||||
}) {
|
||||
function compile(template, options = {}) {
|
||||
// parsing
|
||||
const ast = parse(template, options.customDirectives);
|
||||
const ast = parse(template);
|
||||
// some work
|
||||
const hasSafeContext = template instanceof Node
|
||||
? !(template instanceof Element) || template.querySelector("[t-set], [t-call]") === null
|
||||
@@ -5620,7 +5557,7 @@ function compile(template, options = {
|
||||
}
|
||||
|
||||
// do not modify manually. This file is generated by the release script.
|
||||
const version = "2.5.3";
|
||||
const version = "2.4.0";
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Scheduler
|
||||
@@ -5631,7 +5568,6 @@ class Scheduler {
|
||||
this.frame = 0;
|
||||
this.delayedRenders = [];
|
||||
this.cancelledNodes = new Set();
|
||||
this.processing = false;
|
||||
this.requestAnimationFrame = Scheduler.requestAnimationFrame;
|
||||
}
|
||||
addFiber(fiber) {
|
||||
@@ -5662,10 +5598,6 @@ class Scheduler {
|
||||
}
|
||||
}
|
||||
processTasks() {
|
||||
if (this.processing) {
|
||||
return;
|
||||
}
|
||||
this.processing = true;
|
||||
this.frame = 0;
|
||||
for (let node of this.cancelledNodes) {
|
||||
node._destroy();
|
||||
@@ -5679,7 +5611,6 @@ class Scheduler {
|
||||
this.tasks.delete(task);
|
||||
}
|
||||
}
|
||||
this.processing = false;
|
||||
}
|
||||
processFiber(fiber) {
|
||||
if (fiber.root !== fiber) {
|
||||
@@ -5699,14 +5630,7 @@ class Scheduler {
|
||||
if (!hasError) {
|
||||
fiber.complete();
|
||||
}
|
||||
// at this point, the fiber should have been applied to the DOM, so we can
|
||||
// remove it from the task list. If it is not the case, it means that there
|
||||
// was an error and an error handler triggered a new rendering that recycled
|
||||
// the fiber, so in that case, we actually want to keep the fiber around,
|
||||
// otherwise it will just be ignored.
|
||||
if (fiber.appliedToDom) {
|
||||
this.tasks.delete(fiber);
|
||||
}
|
||||
this.tasks.delete(fiber);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5762,9 +5686,7 @@ class App extends TemplateSet {
|
||||
if (config.env) {
|
||||
this.env = config.env;
|
||||
}
|
||||
const restore = saveCurrent();
|
||||
const node = this.makeNode(Root, props);
|
||||
restore();
|
||||
if (config.env) {
|
||||
this.env = env;
|
||||
}
|
||||
@@ -6090,14 +6012,12 @@ TemplateSet.prototype._compileTemplate = function _compileTemplate(name, templat
|
||||
dev: this.dev,
|
||||
translateFn: this.translateFn,
|
||||
translatableAttributes: this.translatableAttributes,
|
||||
customDirectives: this.customDirectives,
|
||||
hasGlobalValues: this.hasGlobalValues,
|
||||
});
|
||||
};
|
||||
|
||||
export { App, Component, EventBus, OwlError, __info__, batched, blockDom, loadFile, markRaw, markup, mount, onError, onMounted, onPatched, onRendered, onWillDestroy, onWillPatch, onWillRender, onWillStart, onWillUnmount, onWillUpdateProps, reactive, status, toRaw, useChildSubEnv, useComponent, useEffect, useEnv, useExternalListener, useRef, useState, useSubEnv, validate, validateType, whenReady, xml };
|
||||
|
||||
|
||||
__info__.date = '2025-01-10T10:10:53.709Z';
|
||||
__info__.hash = 'b31fa81';
|
||||
__info__.date = '2024-09-30T08:49:29.420Z';
|
||||
__info__.hash = 'eb2b32a';
|
||||
__info__.url = 'https://github.com/odoo/owl';
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@odoo/owl",
|
||||
"version": "2.5.3",
|
||||
"version": "2.4.0",
|
||||
"description": "Odoo Web Library (OWL)",
|
||||
"main": "dist/owl.cjs.js",
|
||||
"module": "dist/owl.es.js",
|
||||
@@ -32,10 +32,7 @@
|
||||
"check-formatting": "prettier {src/*.ts,src/**/*.ts,tests/*.ts,tests/**/*.ts,doc/*.md,doc/**/*.md,tools/devtools/**/*.js} --check",
|
||||
"lint": "eslint src/**/*.ts tests/**/*.ts",
|
||||
"release": "node tools/release.js",
|
||||
"compile_templates": "node tools/compile_owl_templates.mjs"
|
||||
},
|
||||
"bin": {
|
||||
"compile_owl_templates": "tools/compile_owl_templates.mjs"
|
||||
"compile_templates": "node tools/compile_xml.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -49,7 +46,6 @@
|
||||
"homepage": "https://github.com/odoo/owl#readme",
|
||||
"devDependencies": {
|
||||
"@types/jest": "^27.0.1",
|
||||
"@types/jsdom": "^21.1.7",
|
||||
"@types/node": "^14.11.8",
|
||||
"@typescript-eslint/eslint-plugin": "5.48.1",
|
||||
"@typescript-eslint/parser": "5.48.1",
|
||||
@@ -101,8 +97,5 @@
|
||||
"prettier": {
|
||||
"printWidth": 100,
|
||||
"endOfLine": "auto"
|
||||
},
|
||||
"dependencies": {
|
||||
"jsdom": "^25.0.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import pkg from "./package.json";
|
||||
import git from "git-rev-sync";
|
||||
import typescript from "rollup-plugin-typescript2";
|
||||
import typescript from 'rollup-plugin-typescript2';
|
||||
import { terser } from "rollup-plugin-terser";
|
||||
import dts from "rollup-plugin-dts";
|
||||
|
||||
@@ -12,7 +12,7 @@ const ES_FILENAME = "dist/owl.es.js";
|
||||
|
||||
if (pkg.module !== ES_FILENAME || pkg.main !== CJS_FILENAME) {
|
||||
throw new Error("package.json has been modified. Build script should be updated accordingly");
|
||||
}
|
||||
}
|
||||
|
||||
const outro = `
|
||||
__info__.date = '${new Date().toISOString()}';
|
||||
@@ -21,37 +21,39 @@ __info__.url = 'https://github.com/odoo/owl';
|
||||
`;
|
||||
|
||||
switch (process.argv[4]) {
|
||||
case "compiler":
|
||||
(input = "src/compiler/index.ts"),
|
||||
(output = [getConfigForFormat("cjs", "dist/compiler.js", "")]);
|
||||
case "compiler":
|
||||
input = "src/compiler/index.ts",
|
||||
output = [
|
||||
getConfigForFormat('cjs', 'dist/compiler.js', ''),
|
||||
]
|
||||
break;
|
||||
case "runtime":
|
||||
input = "src/runtime/index.ts";
|
||||
output = [
|
||||
getConfigForFormat("esm", addSuffix(ES_FILENAME, "runtime"), outro),
|
||||
getConfigForFormat("cjs", addSuffix(CJS_FILENAME, "runtime"), outro),
|
||||
getConfigForFormat("iife", addSuffix(IIFE_FILENAME, "runtime"), outro),
|
||||
getConfigForFormat("iife", addSuffix(IIFE_FILENAME, "runtime"), outro, true),
|
||||
];
|
||||
getConfigForFormat('esm', addSuffix(ES_FILENAME, 'runtime'), outro),
|
||||
getConfigForFormat('cjs', addSuffix(CJS_FILENAME, 'runtime'), outro),
|
||||
getConfigForFormat('iife', addSuffix(IIFE_FILENAME, 'runtime'), outro),
|
||||
getConfigForFormat('iife', addSuffix(IIFE_FILENAME, 'runtime'), outro, true),
|
||||
]
|
||||
break;
|
||||
default:
|
||||
(input = "src/index.ts"),
|
||||
(output = [
|
||||
getConfigForFormat("esm", ES_FILENAME, outro),
|
||||
getConfigForFormat("cjs", CJS_FILENAME, outro),
|
||||
getConfigForFormat("iife", IIFE_FILENAME, outro),
|
||||
getConfigForFormat("iife", IIFE_FILENAME, outro, true),
|
||||
]);
|
||||
}
|
||||
input = "src/index.ts",
|
||||
output = [
|
||||
getConfigForFormat('esm', ES_FILENAME, outro),
|
||||
getConfigForFormat('cjs', CJS_FILENAME, outro),
|
||||
getConfigForFormat('iife', IIFE_FILENAME, outro),
|
||||
getConfigForFormat('iife', IIFE_FILENAME, outro, true),
|
||||
]
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate from a string depicting a path a new path for the minified version.
|
||||
* @param {string} pkgFileName file name
|
||||
*/
|
||||
function addSuffix(pkgFileName, suffix) {
|
||||
const parts = pkgFileName.split(".");
|
||||
const parts = pkgFileName.split('.');
|
||||
parts.splice(parts.length - 1, 0, suffix);
|
||||
return parts.join(".");
|
||||
return parts.join('.');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -69,7 +71,7 @@ function getConfigForFormat(format, generatedFileName, outro, minified = false)
|
||||
outro: outro,
|
||||
freeze: false,
|
||||
plugins: minified ? [terser()] : [],
|
||||
indent: " ", // indent with 4 spaces
|
||||
indent: ' ', // indent with 4 spaces
|
||||
};
|
||||
}
|
||||
|
||||
@@ -79,19 +81,9 @@ export default [
|
||||
output,
|
||||
plugins: [
|
||||
typescript({
|
||||
useTsconfigDeclarationDir: true,
|
||||
useTsconfigDeclarationDir: true
|
||||
}),
|
||||
],
|
||||
},
|
||||
{
|
||||
input: "src/compiler/standalone/index.ts",
|
||||
output: [{ file: "dist/compile_templates.mjs", format: "es" }],
|
||||
external: ["fs", "fs/promises", "path", "jsdom"],
|
||||
plugins: [
|
||||
typescript({
|
||||
useTsconfigDeclarationDir: true,
|
||||
}),
|
||||
],
|
||||
]
|
||||
},
|
||||
{
|
||||
input: "dist/types/index.d.ts",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { OwlError } from "../common/owl_error";
|
||||
import { OwlError } from "./owl_error";
|
||||
|
||||
/**
|
||||
* Owl QWeb Expression Parser
|
||||
@@ -28,7 +28,7 @@ import { OwlError } from "../common/owl_error";
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
const RESERVED_WORDS =
|
||||
"true,false,NaN,null,undefined,debugger,console,window,in,instanceof,new,function,return,eval,void,Math,RegExp,Array,Object,Date,__globals__".split(
|
||||
"true,false,NaN,null,undefined,debugger,console,window,in,instanceof,new,function,return,eval,void,Math,RegExp,Array,Object,Date".split(
|
||||
","
|
||||
);
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
export type customDirectives = Record<
|
||||
string,
|
||||
(node: Element, value: string, modifier: string[]) => void
|
||||
>;
|
||||
@@ -4,7 +4,7 @@ import {
|
||||
interpolate,
|
||||
INTERP_REGEXP,
|
||||
replaceDynamicParts,
|
||||
} from "./inline_expressions";
|
||||
} from "../common/inline_expressions";
|
||||
import {
|
||||
AST,
|
||||
ASTComment,
|
||||
@@ -43,7 +43,6 @@ export interface Config {
|
||||
export interface CodeGenOptions extends Config {
|
||||
hasSafeContext?: boolean;
|
||||
name?: string;
|
||||
hasGlobalValues: boolean;
|
||||
}
|
||||
|
||||
// using a non-html document so that <inner/outer>HTML serializes as XML instead
|
||||
@@ -287,9 +286,6 @@ export class CodeGenerator {
|
||||
this.dev = options.dev || false;
|
||||
this.ast = ast;
|
||||
this.templateName = options.name;
|
||||
if (options.hasGlobalValues) {
|
||||
this.helpers.add("__globals__");
|
||||
}
|
||||
}
|
||||
|
||||
generateCode(): string {
|
||||
@@ -1156,7 +1152,7 @@ export class CodeGenerator {
|
||||
case "translate":
|
||||
break;
|
||||
default:
|
||||
throw new OwlError(`Invalid prop suffix: ${suffix}`);
|
||||
throw new OwlError("Invalid prop suffix");
|
||||
}
|
||||
}
|
||||
name = /^[a-z_]+$/i.test(name) ? name : `'${name}'`;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import type { customDirectives } from "../common/types";
|
||||
import type { TemplateSet } from "../runtime/template_set";
|
||||
import type { BDom } from "../runtime/blockdom";
|
||||
import { CodeGenerator, Config } from "./code_generator";
|
||||
@@ -11,17 +10,13 @@ export type TemplateFunction = (app: TemplateSet, bdom: any, helpers: any) => Te
|
||||
|
||||
interface CompileOptions extends Config {
|
||||
name?: string;
|
||||
customDirectives?: customDirectives;
|
||||
hasGlobalValues: boolean;
|
||||
}
|
||||
export function compile(
|
||||
template: string | Element,
|
||||
options: CompileOptions = {
|
||||
hasGlobalValues: false,
|
||||
}
|
||||
options: CompileOptions = {}
|
||||
): TemplateFunction {
|
||||
// parsing
|
||||
const ast = parse(template, options.customDirectives);
|
||||
const ast = parse(template);
|
||||
|
||||
// some work
|
||||
const hasSafeContext =
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { OwlError } from "../common/owl_error";
|
||||
import type { customDirectives } from "../common/types";
|
||||
import { parseXML } from "../common/utils";
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
@@ -199,26 +198,23 @@ export type AST =
|
||||
// -----------------------------------------------------------------------------
|
||||
const cache: WeakMap<Element, AST> = new WeakMap();
|
||||
|
||||
export function parse(xml: string | Element, customDir?: customDirectives): AST {
|
||||
const ctx = {
|
||||
inPreTag: false,
|
||||
customDirectives: customDir,
|
||||
};
|
||||
export function parse(xml: string | Element): AST {
|
||||
if (typeof xml === "string") {
|
||||
const elem = parseXML(`<t>${xml}</t>`).firstChild as Element;
|
||||
return _parse(elem, ctx);
|
||||
return _parse(elem);
|
||||
}
|
||||
let ast = cache.get(xml);
|
||||
if (!ast) {
|
||||
// we clone here the xml to prevent modifying it in place
|
||||
ast = _parse(xml.cloneNode(true) as Element, ctx);
|
||||
ast = _parse(xml.cloneNode(true) as Element);
|
||||
cache.set(xml, ast);
|
||||
}
|
||||
return ast;
|
||||
}
|
||||
|
||||
function _parse(xml: Element, ctx: ParsingContext): AST {
|
||||
function _parse(xml: Element): AST {
|
||||
normalizeXML(xml);
|
||||
const ctx = { inPreTag: false };
|
||||
return parseNode(xml, ctx) || { type: ASTType.Text, value: "" };
|
||||
}
|
||||
|
||||
@@ -226,7 +222,6 @@ interface ParsingContext {
|
||||
tModelInfo?: TModelInfo | null;
|
||||
nameSpace?: string;
|
||||
inPreTag: boolean;
|
||||
customDirectives?: customDirectives;
|
||||
}
|
||||
|
||||
function parseNode(node: Node, ctx: ParsingContext): AST | null {
|
||||
@@ -234,7 +229,6 @@ function parseNode(node: Node, ctx: ParsingContext): AST | null {
|
||||
return parseTextCommentNode(node, ctx);
|
||||
}
|
||||
return (
|
||||
parseTCustom(node, ctx) ||
|
||||
parseTDebugLog(node, ctx) ||
|
||||
parseTForEach(node, ctx) ||
|
||||
parseTIf(node, ctx) ||
|
||||
@@ -283,37 +277,6 @@ function parseTextCommentNode(node: Node, ctx: ParsingContext): AST | null {
|
||||
return null;
|
||||
}
|
||||
|
||||
function parseTCustom(node: Element, ctx: ParsingContext): AST | null {
|
||||
if (!ctx.customDirectives) {
|
||||
return null;
|
||||
}
|
||||
const nodeAttrsNames = node.getAttributeNames();
|
||||
for (let attr of nodeAttrsNames) {
|
||||
if (attr === "t-custom" || attr === "t-custom-") {
|
||||
throw new OwlError("Missing custom directive name with t-custom directive");
|
||||
}
|
||||
if (attr.startsWith("t-custom-")) {
|
||||
const directiveName = attr.split(".")[0].slice(9);
|
||||
const customDirective = ctx.customDirectives[directiveName];
|
||||
if (!customDirective) {
|
||||
throw new OwlError(`Custom directive "${directiveName}" is not defined`);
|
||||
}
|
||||
const value = node.getAttribute(attr)!;
|
||||
const modifiers = attr.split(".").slice(1);
|
||||
node.removeAttribute(attr);
|
||||
try {
|
||||
customDirective(node, value, modifiers);
|
||||
} catch (error) {
|
||||
throw new OwlError(
|
||||
`Custom directive "${directiveName}" throw the following error: ${error}`
|
||||
);
|
||||
}
|
||||
return parseNode(node, ctx);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// debugging
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
// -----------------------------------------------------------------------------
|
||||
// This file exports a function that allows compiling templates ahead of time.
|
||||
// It is used by the "compile_owl_template" command registered in the "bin"
|
||||
// section of owl's package.json
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
import { readdir, readFile, stat } from "fs/promises";
|
||||
import path from "path";
|
||||
import "./setup_jsdom";
|
||||
// Owl imports must be made after setting up jsdom in the global namespace
|
||||
import { compile } from "..";
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// helpers
|
||||
// -----------------------------------------------------------------------------
|
||||
async function getXmlFiles(paths: string[]): Promise<string[]> {
|
||||
return (
|
||||
await Promise.all(
|
||||
paths.map(async (file) => {
|
||||
const stats = await stat(path.join(file));
|
||||
if (stats.isDirectory()) {
|
||||
return await getXmlFiles(
|
||||
(await readdir(file)).map((fileName) => path.join(file, fileName))
|
||||
);
|
||||
}
|
||||
if (file.endsWith(".xml")) {
|
||||
return file;
|
||||
}
|
||||
return [];
|
||||
})
|
||||
)
|
||||
).flat();
|
||||
}
|
||||
|
||||
// adapted from https://medium.com/@mhagemann/the-ultimate-way-to-slugify-a-url-string-in-javascript-b8e4a0d849e1
|
||||
const a = "·-_,:;";
|
||||
const p = new RegExp(a.split("").join("|"), "g");
|
||||
|
||||
function slugify(str: string) {
|
||||
return str
|
||||
.replace(/\//g, "") // remove /
|
||||
.replace(/\./g, "_") // Replace . with _
|
||||
.replace(p, (c) => "_") // Replace special characters
|
||||
.replace(/&/g, "_and_") // Replace & with ‘and’
|
||||
.replace(/[^\w\-]+/g, ""); // Remove all non-word characters
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// main
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
export async function compileTemplates(paths: string[]) {
|
||||
const files = await getXmlFiles(paths);
|
||||
process.stdout.write(`Processing ${files.length} files`);
|
||||
let xmlStrings = await Promise.all(files.map((file) => readFile(file, "utf8")));
|
||||
|
||||
const templates = [];
|
||||
const errors = [];
|
||||
|
||||
for (let i = 0; i < files.length; i++) {
|
||||
const fileName = files[i];
|
||||
const fileContent = xmlStrings[i];
|
||||
process.stdout.write(`.`);
|
||||
const parser = new DOMParser();
|
||||
const doc = parser.parseFromString(fileContent, "text/xml");
|
||||
for (const template of doc.querySelectorAll("[t-name]")) {
|
||||
const name = template.getAttribute("t-name");
|
||||
if (template.hasAttribute("owl")) {
|
||||
template.removeAttribute("owl");
|
||||
}
|
||||
const fnName = slugify(name!);
|
||||
try {
|
||||
const fn = compile(template).toString().replace("anonymous", fnName);
|
||||
templates.push(`"${name}": ${fn},\n`);
|
||||
} catch (e) {
|
||||
errors.push({ name, fileName, e });
|
||||
}
|
||||
}
|
||||
}
|
||||
process.stdout.write(`\n`);
|
||||
|
||||
for (let { name, fileName, e } of errors) {
|
||||
console.warn(`Error while compiling '${name}' (in file ${fileName})`);
|
||||
console.error(e);
|
||||
}
|
||||
console.log(`${templates.length} templates compiled`);
|
||||
|
||||
return `export const templates = {\n ${templates.join("\n")} \n}`;
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
import jsdom from "jsdom";
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// add global DOM stuff for compiler. Needs to be in a separate file so rollup
|
||||
// doesn't hoist the owl imports above this block of code.
|
||||
// -----------------------------------------------------------------------------
|
||||
var document = new jsdom.JSDOM("", {});
|
||||
var window = document.window;
|
||||
global.document = window.document;
|
||||
global.window = window as unknown as Window & typeof globalThis;
|
||||
global.DOMParser = window.DOMParser;
|
||||
global.Element = window.Element;
|
||||
global.Node = window.Node;
|
||||
@@ -12,7 +12,5 @@ TemplateSet.prototype._compileTemplate = function _compileTemplate(
|
||||
dev: this.dev,
|
||||
translateFn: this.translateFn,
|
||||
translatableAttributes: this.translatableAttributes,
|
||||
customDirectives: this.customDirectives,
|
||||
hasGlobalValues: this.hasGlobalValues,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { OwlError } from "../common/owl_error";
|
||||
import { version } from "../version";
|
||||
import { Component, ComponentConstructor, Props } from "./component";
|
||||
import { ComponentNode, saveCurrent } from "./component_node";
|
||||
import { nodeErrorHandlers, handleError } from "./error_handling";
|
||||
import { OwlError } from "../common/owl_error";
|
||||
import { Fiber, RootFiber, MountOptions } from "./fibers";
|
||||
import { handleError, nodeErrorHandlers } from "./error_handling";
|
||||
import { Fiber, MountOptions, RootFiber } from "./fibers";
|
||||
import { reactive, toRaw } from "./reactivity";
|
||||
import { Scheduler } from "./scheduler";
|
||||
import { validateProps } from "./template_helpers";
|
||||
import { TemplateSet, TemplateSetConfig } from "./template_set";
|
||||
import { validateTarget } from "./utils";
|
||||
import { toRaw, reactive } from "./reactivity";
|
||||
|
||||
// reimplement dev mode stuff see last change in 0f7a8289a6fb8387c3c1af41c6664b2a8448758f
|
||||
|
||||
@@ -53,7 +53,7 @@ declare global {
|
||||
}
|
||||
|
||||
interface Root<P extends Props, E> {
|
||||
node: ComponentNode<P, E>;
|
||||
node: ComponentNode<P, E> | null;
|
||||
mount(target: HTMLElement | ShadowRoot, options?: MountOptions): Promise<Component<P, E>>;
|
||||
destroy(): void;
|
||||
}
|
||||
@@ -74,9 +74,10 @@ export class App<
|
||||
props: P;
|
||||
env: E;
|
||||
scheduler = new Scheduler();
|
||||
subRoots: Set<ComponentNode> = new Set();
|
||||
root: ComponentNode<P, E> | null = null;
|
||||
subRoots: Set<Root<any, any>> = new Set();
|
||||
root: Root<P, E> | null = null;
|
||||
warnIfNoStaticProps: boolean;
|
||||
_lastRootEl: HTMLElement | ShadowRoot | null = null; // temporary ref to propagate to roots
|
||||
|
||||
constructor(Root: ComponentConstructor<P, E>, config: AppConfig<P, E> = {}) {
|
||||
super(config);
|
||||
@@ -101,10 +102,8 @@ export class App<
|
||||
target: HTMLElement | ShadowRoot,
|
||||
options?: MountOptions
|
||||
): Promise<Component<P, E> & InstanceType<T>> {
|
||||
const root = this.createRoot(this.Root, { props: this.props });
|
||||
this.root = root.node;
|
||||
this.subRoots.delete(root.node);
|
||||
return root.mount(target, options) as any;
|
||||
this.root = this.createRoot(this.Root, { props: this.props });
|
||||
return this.root.mount(target, options) as any;
|
||||
}
|
||||
|
||||
createRoot<Props extends object, SubEnv = any>(
|
||||
@@ -112,26 +111,38 @@ export class App<
|
||||
config: RootConfig<Props, SubEnv> = {}
|
||||
): Root<Props, SubEnv> {
|
||||
const props = config.props || ({} as Props);
|
||||
// hack to make sure the sub root get the sub env if necessary. for owl 3,
|
||||
// would be nice to rethink the initialization process to make sure that
|
||||
// we can create a ComponentNode and give it explicitely the env, instead
|
||||
// of looking it up in the app
|
||||
const env = this.env;
|
||||
if (config.env) {
|
||||
this.env = config.env as any;
|
||||
}
|
||||
|
||||
const restore = saveCurrent();
|
||||
const node = this.makeNode(Root, props);
|
||||
restore();
|
||||
if (config.env) {
|
||||
this.env = env;
|
||||
}
|
||||
this.subRoots.add(node);
|
||||
return {
|
||||
node,
|
||||
const root: Root<Props, SubEnv> = {
|
||||
node: null,
|
||||
mount: (target: HTMLElement | ShadowRoot, options?: MountOptions) => {
|
||||
App.validateTarget(target);
|
||||
|
||||
// hack to make sure the sub root get the sub env if necessary. for owl 3,
|
||||
// would be nice to rethink the initialization process to make sure that
|
||||
// we can create a ComponentNode and give it explicitely the env, instead
|
||||
// of looking it up in the app
|
||||
if (config.env) {
|
||||
this.env = config.env as any;
|
||||
}
|
||||
const restore = saveCurrent();
|
||||
if (options?.position === "attach") {
|
||||
if (Root.template) {
|
||||
throw new Error("Cannot attach a component with a template");
|
||||
}
|
||||
this._lastRootEl = target;
|
||||
} else {
|
||||
if (!Root.template) {
|
||||
// no template => trigger an error
|
||||
this.getTemplate("");
|
||||
}
|
||||
}
|
||||
const node = this.makeNode(Root, props);
|
||||
root.node = node;
|
||||
this._lastRootEl = null;
|
||||
restore();
|
||||
if (config.env) {
|
||||
this.env = env;
|
||||
}
|
||||
if (this.dev) {
|
||||
validateProps(Root, props, { __owl__: { app: this } });
|
||||
}
|
||||
@@ -139,11 +150,16 @@ export class App<
|
||||
return prom;
|
||||
},
|
||||
destroy: () => {
|
||||
this.subRoots.delete(node);
|
||||
node.destroy();
|
||||
this.scheduler.processTasks();
|
||||
this.subRoots.delete(root);
|
||||
if (root.node) {
|
||||
root.node?.destroy();
|
||||
this.scheduler.processTasks();
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
this.subRoots.add(root);
|
||||
return root;
|
||||
}
|
||||
|
||||
makeNode(Component: ComponentConstructor, props: any): ComponentNode {
|
||||
@@ -178,13 +194,17 @@ export class App<
|
||||
}
|
||||
|
||||
destroy() {
|
||||
if (this.root) {
|
||||
for (let subroot of this.subRoots) {
|
||||
subroot.destroy();
|
||||
}
|
||||
this.root.destroy();
|
||||
this.scheduler.processTasks();
|
||||
const roots = [...this.subRoots].reverse();
|
||||
for (let root of roots) {
|
||||
root.destroy();
|
||||
}
|
||||
// if (this.root) {
|
||||
// for (let subroot of this.subRoots) {
|
||||
// subroot.destroy();
|
||||
// }
|
||||
// this.root.destroy();
|
||||
this.scheduler.processTasks();
|
||||
// }
|
||||
apps.delete(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ export type Props = { [key: string]: any };
|
||||
|
||||
interface StaticComponentProperties {
|
||||
template: string;
|
||||
dynamicContent?: { [spec: string]: string };
|
||||
defaultProps?: any;
|
||||
props?: Schema;
|
||||
components?: { [componentName: string]: ComponentConstructor };
|
||||
|
||||
@@ -6,7 +6,9 @@ import { OwlError } from "../common/owl_error";
|
||||
import { Fiber, makeChildFiber, makeRootFiber, MountFiber, MountOptions } from "./fibers";
|
||||
import { clearReactivesForCallback, getSubscriptions, reactive, targets } from "./reactivity";
|
||||
import { STATUS } from "./status";
|
||||
import { batched, Callback } from "./utils";
|
||||
import { batched, Callback, Markup } from "./utils";
|
||||
import { xml } from "./template_set";
|
||||
import { compileExpr } from "../common/inline_expressions";
|
||||
|
||||
let currentNode: ComponentNode | null = null;
|
||||
|
||||
@@ -124,11 +126,102 @@ export class ComponentNode<P extends Props = any, E = any> implements VNode<Comp
|
||||
}
|
||||
this.component = new C(props, env, this);
|
||||
const ctx = Object.assign(Object.create(this.component), { this: this.component });
|
||||
this.renderFn = app.getTemplate(C.template).bind(this.component, ctx, this);
|
||||
if (C.template) {
|
||||
this.renderFn = app.getTemplate(C.template).bind(this.component, ctx, this);
|
||||
} else {
|
||||
// component will be attached
|
||||
this.renderFn = app.getTemplate(xml``).bind(this.component, ctx, this);
|
||||
if (C.dynamicContent) {
|
||||
this.prepareAttach(app._lastRootEl!, C.dynamicContent, ctx);
|
||||
}
|
||||
}
|
||||
this.component.setup();
|
||||
currentNode = null;
|
||||
}
|
||||
|
||||
prepareAttach(
|
||||
el: HTMLElement | ShadowRoot,
|
||||
dynamicContent: { [spec: string]: string },
|
||||
ctx: any
|
||||
) {
|
||||
const attrs: { selector: string; attr: string; fn: Function }[] = [];
|
||||
const handlers: { selector: string; event: string; fn: any }[] = [];
|
||||
const tOuts: { selector: string; fn: Function }[] = [];
|
||||
for (let key in dynamicContent) {
|
||||
const value = dynamicContent[key];
|
||||
const parts = key.split(":");
|
||||
if (parts[1].startsWith("t-att-")) {
|
||||
const attr = parts[1].slice(6);
|
||||
const fn = new Function("ctx", `return ${compileExpr(value)};`);
|
||||
attrs.push({
|
||||
selector: parts[0],
|
||||
attr,
|
||||
fn,
|
||||
});
|
||||
}
|
||||
if (parts[1].startsWith("t-on-")) {
|
||||
const event = parts[1].slice(5);
|
||||
// const fn = new Function("ctx", "ev", `${compileExpr(value)}(ev);`);
|
||||
const fn = (ev: any) => (this as any).component[value](ev);
|
||||
handlers.push({
|
||||
selector: parts[0],
|
||||
event,
|
||||
fn,
|
||||
});
|
||||
}
|
||||
if (parts[1] === "t-out") {
|
||||
const fn = new Function("ctx", `return ${compileExpr(value)};`);
|
||||
tOuts.push({ selector: parts[0], fn });
|
||||
}
|
||||
}
|
||||
const handleAttrs = () => {
|
||||
for (let attr of attrs) {
|
||||
const val = attr.fn.call(this.component, ctx);
|
||||
// todo: cache the queryselector result?
|
||||
const target = attr.selector === "root" ? el : (el.querySelector(attr.selector) as any);
|
||||
if (target) {
|
||||
target.setAttribute(attr.attr, val);
|
||||
}
|
||||
}
|
||||
};
|
||||
const handleEvents = () => {
|
||||
for (let handler of handlers) {
|
||||
// const val = attr.fn.call(this.component, ctx);
|
||||
// todo: cache the queryselector result?
|
||||
const target =
|
||||
handler.selector === "root" ? el : (el.querySelector(handler.selector) as any);
|
||||
if (target) {
|
||||
target.addEventListener(handler.event, handler.fn);
|
||||
}
|
||||
}
|
||||
};
|
||||
const handleTOuts = () => {
|
||||
for (let tOut of tOuts) {
|
||||
const val = tOut.fn.call(this.component, ctx);
|
||||
// todo: cache the queryselector result?
|
||||
const target = tOut.selector === "root" ? el : (el.querySelector(tOut.selector) as any);
|
||||
if (target) {
|
||||
if (val instanceof Markup) {
|
||||
target.innerHTML = val as any;
|
||||
} else {
|
||||
target.textContent = val;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
if (attrs.length) {
|
||||
this.mounted.push(handleAttrs);
|
||||
this.patched.push(handleAttrs);
|
||||
}
|
||||
if (handlers.length) {
|
||||
this.mounted.push(handleEvents);
|
||||
}
|
||||
if (tOuts.length) {
|
||||
this.mounted.push(handleTOuts);
|
||||
this.patched.push(handleTOuts);
|
||||
}
|
||||
}
|
||||
|
||||
mountComponent(target: any, options?: MountOptions) {
|
||||
const fiber = new MountFiber(this, target, options);
|
||||
this.app.scheduler.addFiber(fiber);
|
||||
|
||||
@@ -30,13 +30,6 @@ export function makeRootFiber(node: ComponentNode): Fiber {
|
||||
fibersInError.delete(current);
|
||||
fibersInError.delete(root);
|
||||
current.appliedToDom = false;
|
||||
if (current instanceof RootFiber) {
|
||||
// it is possible that this fiber is a fiber that crashed while being
|
||||
// mounted, so the mounted list is possibly corrupted. We restore it to
|
||||
// its normal initial state (which is empty list or a list with a mount
|
||||
// fiber.
|
||||
current.mounted = current instanceof MountFiber ? [current] : [];
|
||||
}
|
||||
}
|
||||
return current;
|
||||
}
|
||||
@@ -159,7 +152,6 @@ export class RootFiber extends Fiber {
|
||||
const node = this.node;
|
||||
this.locked = true;
|
||||
let current: Fiber | undefined = undefined;
|
||||
let mountedFibers = this.mounted;
|
||||
try {
|
||||
// Step 1: calling all willPatch lifecycle hooks
|
||||
for (current of this.willPatch) {
|
||||
@@ -181,6 +173,7 @@ export class RootFiber extends Fiber {
|
||||
this.locked = false;
|
||||
|
||||
// Step 4: calling all mounted lifecycle hooks
|
||||
let mountedFibers = this.mounted;
|
||||
while ((current = mountedFibers.pop())) {
|
||||
current = current;
|
||||
if (current.appliedToDom) {
|
||||
@@ -201,15 +194,6 @@ export class RootFiber extends Fiber {
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
// if mountedFibers is not empty, this means that a crash occured while
|
||||
// calling the mounted hooks of some component. So, there may still be
|
||||
// some component that have been mounted, but for which the mounted hooks
|
||||
// have not been called. Here, we remove the willUnmount hooks for these
|
||||
// specific component to prevent a worse situation (willUnmount being
|
||||
// called even though mounted has not been called)
|
||||
for (let fiber of mountedFibers) {
|
||||
fiber.node.willUnmount = [];
|
||||
}
|
||||
this.locked = false;
|
||||
node.app.handleError({ fiber: current || this, error: e });
|
||||
}
|
||||
@@ -223,7 +207,7 @@ export class RootFiber extends Fiber {
|
||||
}
|
||||
}
|
||||
|
||||
type Position = "first-child" | "last-child";
|
||||
type Position = "first-child" | "last-child" | "attach";
|
||||
|
||||
export interface MountOptions {
|
||||
position?: Position;
|
||||
|
||||
@@ -136,3 +136,20 @@ export function useExternalListener(
|
||||
onMounted(() => target.addEventListener(eventName, boundHandler, eventParams));
|
||||
onWillUnmount(() => target.removeEventListener(eventName, boundHandler, eventParams));
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// useAttachedEl
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* The purpose of this hook is to allow attached components to get a reference to
|
||||
* the element they have been attached on.
|
||||
*/
|
||||
export function useAttachedEl(): HTMLElement {
|
||||
const node = getCurrent();
|
||||
const el = node.app._lastRootEl as HTMLElement;
|
||||
if (!el) {
|
||||
throw new Error("useAttachedEl can only be called with component that are attached");
|
||||
}
|
||||
return el;
|
||||
}
|
||||
|
||||
@@ -93,14 +93,7 @@ export class Scheduler {
|
||||
if (!hasError) {
|
||||
fiber.complete();
|
||||
}
|
||||
// at this point, the fiber should have been applied to the DOM, so we can
|
||||
// remove it from the task list. If it is not the case, it means that there
|
||||
// was an error and an error handler triggered a new rendering that recycled
|
||||
// the fiber, so in that case, we actually want to keep the fiber around,
|
||||
// otherwise it will just be ignored.
|
||||
if (fiber.appliedToDom) {
|
||||
this.tasks.delete(fiber);
|
||||
}
|
||||
this.tasks.delete(fiber);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import { Portal, portalTemplate } from "./portal";
|
||||
import { helpers } from "./template_helpers";
|
||||
import { OwlError } from "../common/owl_error";
|
||||
import { parseXML } from "../common/utils";
|
||||
import type { customDirectives } from "../common/types";
|
||||
|
||||
const bdom = { text, createBlock, list, multi, html, toggler, comment };
|
||||
|
||||
@@ -15,8 +14,6 @@ export interface TemplateSetConfig {
|
||||
translateFn?: (s: string) => string;
|
||||
templates?: string | Document | Record<string, string>;
|
||||
getTemplate?: (s: string) => Element | Function | string | void;
|
||||
customDirectives?: customDirectives;
|
||||
globalValues?: object;
|
||||
}
|
||||
|
||||
export class TemplateSet {
|
||||
@@ -30,9 +27,6 @@ export class TemplateSet {
|
||||
translateFn?: (s: string) => string;
|
||||
translatableAttributes?: string[];
|
||||
Portal = Portal;
|
||||
customDirectives: customDirectives;
|
||||
runtimeUtils: object;
|
||||
hasGlobalValues: boolean;
|
||||
|
||||
constructor(config: TemplateSetConfig = {}) {
|
||||
this.dev = config.dev || false;
|
||||
@@ -48,9 +42,6 @@ export class TemplateSet {
|
||||
}
|
||||
}
|
||||
this.getRawTemplate = config.getTemplate;
|
||||
this.customDirectives = config.customDirectives || {};
|
||||
this.runtimeUtils = { ...helpers, __globals__: config.globalValues || {} };
|
||||
this.hasGlobalValues = Boolean(config.globalValues && Object.keys(config.globalValues).length);
|
||||
}
|
||||
|
||||
addTemplate(name: string, template: string | Element) {
|
||||
@@ -106,7 +97,7 @@ export class TemplateSet {
|
||||
this.templates[name] = function (context, parent) {
|
||||
return templates[name].call(this, context, parent);
|
||||
};
|
||||
const template = templateFn(this, bdom, this.runtimeUtils);
|
||||
const template = templateFn(this, bdom, helpers);
|
||||
this.templates[name] = template;
|
||||
}
|
||||
return this.templates[name];
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
// do not modify manually. This file is generated by the release script.
|
||||
export const version = "2.5.3";
|
||||
export const version = "2.4.0";
|
||||
|
||||
@@ -43,21 +43,6 @@ exports[`app app: clear scheduler tasks and destroy cancelled nodes immediately
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`app can add functions to the bdom 1`] = `
|
||||
"function anonymous(app, bdom, helpers
|
||||
) {
|
||||
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||
let { __globals__ } = helpers;
|
||||
|
||||
let block1 = createBlock(\`<div class=\\"my-div\\" block-handler-0=\\"click\\"/>\`);
|
||||
|
||||
return function template(ctx, node, key = \\"\\") {
|
||||
let hdlr1 = [()=>__globals__.plop('click'), ctx];
|
||||
return block1([hdlr1]);
|
||||
}
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`app can call processTask twice in a row without crashing 1`] = `
|
||||
"function anonymous(app, bdom, helpers
|
||||
) {
|
||||
|
||||
@@ -94,17 +94,6 @@ exports[`subroot can create a root in a setup function, then use a hook 1`] = `
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`subroot can create a root in a setup function, then use a hook 2`] = `
|
||||
"function anonymous(app, bdom, helpers
|
||||
) {
|
||||
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||
|
||||
return function template(ctx, node, key = \\"\\") {
|
||||
return text(\`c\`);
|
||||
}
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`subroot can mount subroot 1`] = `
|
||||
"function anonymous(app, bdom, helpers
|
||||
) {
|
||||
|
||||
@@ -201,22 +201,4 @@ describe("app", () => {
|
||||
await app.mount(fixture);
|
||||
expect(fixture.innerHTML).toBe("parent<div></div>");
|
||||
});
|
||||
|
||||
test("can add functions to the bdom", async () => {
|
||||
const steps: string[] = [];
|
||||
class SomeComponent extends Component {
|
||||
static template = xml`<div t-on-click="() => __globals__.plop('click')" class="my-div"/>`;
|
||||
}
|
||||
const app = new App(SomeComponent, {
|
||||
globalValues: {
|
||||
plop: (string: any) => {
|
||||
steps.push(string);
|
||||
},
|
||||
},
|
||||
});
|
||||
await app.mount(fixture);
|
||||
expect(fixture.innerHTML).toBe(`<div class="my-div"></div>`);
|
||||
fixture.querySelector("div")!.click();
|
||||
expect(steps).toEqual(["click"]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`t-custom can use t-custom directive on a node 1`] = `
|
||||
"function anonymous(app, bdom, helpers
|
||||
) {
|
||||
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||
|
||||
let block1 = createBlock(\`<div class=\\"my-div\\" block-handler-0=\\"click\\"/>\`);
|
||||
|
||||
return function template(ctx, node, key = \\"\\") {
|
||||
let hdlr1 = [ctx['click'], ctx];
|
||||
return block1([hdlr1]);
|
||||
}
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`t-custom can use t-custom directive with modifiers on a node 1`] = `
|
||||
"function anonymous(app, bdom, helpers
|
||||
) {
|
||||
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||
|
||||
let block1 = createBlock(\`<div class=\\"my-div\\" block-handler-0=\\"click\\"/>\`);
|
||||
|
||||
return function template(ctx, node, key = \\"\\") {
|
||||
let hdlr1 = [ctx['click'], ctx];
|
||||
return block1([hdlr1]);
|
||||
}
|
||||
}"
|
||||
`;
|
||||
@@ -1,4 +1,4 @@
|
||||
import { compileExpr, tokenize } from "../../src/compiler/inline_expressions";
|
||||
import { compileExpr, tokenize } from "../../src/common/inline_expressions";
|
||||
|
||||
describe("tokenizer", () => {
|
||||
test("simple tokens", () => {
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
import { App, Component, xml } from "../../src";
|
||||
import { makeTestFixture, snapshotEverything } from "../helpers";
|
||||
|
||||
let fixture: HTMLElement;
|
||||
|
||||
snapshotEverything();
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = makeTestFixture();
|
||||
});
|
||||
|
||||
describe("t-custom", () => {
|
||||
test("can use t-custom directive on a node", async () => {
|
||||
const steps: string[] = [];
|
||||
class SomeComponent extends Component {
|
||||
static template = xml`<div t-custom-plop="click" class="my-div"/>`;
|
||||
click() {
|
||||
steps.push("clicked");
|
||||
}
|
||||
}
|
||||
const app = new App(SomeComponent, {
|
||||
customDirectives: {
|
||||
plop: (node, value) => {
|
||||
node.setAttribute("t-on-click", value);
|
||||
},
|
||||
},
|
||||
});
|
||||
await app.mount(fixture);
|
||||
expect(fixture.innerHTML).toBe(`<div class="my-div"></div>`);
|
||||
fixture.querySelector("div")!.click();
|
||||
expect(steps).toEqual(["clicked"]);
|
||||
});
|
||||
|
||||
test("can use t-custom directive with modifiers on a node", async () => {
|
||||
const steps: string[] = [];
|
||||
class SomeComponent extends Component {
|
||||
static template = xml`<div t-custom-plop.mouse.stop="click" class="my-div"/>`;
|
||||
click() {
|
||||
steps.push("clicked");
|
||||
}
|
||||
}
|
||||
const app = new App(SomeComponent, {
|
||||
customDirectives: {
|
||||
plop: (node, value, modifiers) => {
|
||||
node.setAttribute("t-on-click", value);
|
||||
for (let mod of modifiers) {
|
||||
steps.push(mod);
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
await app.mount(fixture);
|
||||
expect(fixture.innerHTML).toBe(`<div class="my-div"></div>`);
|
||||
fixture.querySelector("div")!.click();
|
||||
expect(steps).toEqual(["mouse", "stop", "clicked"]);
|
||||
});
|
||||
});
|
||||
@@ -320,50 +320,6 @@ exports[`can catch errors can catch an error in a component render function 3`]
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`can catch errors can catch an error in onmounted 1`] = `
|
||||
"function anonymous(app, bdom, helpers
|
||||
) {
|
||||
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||
const comp1 = app.createComponent(null, false, false, false, []);
|
||||
|
||||
return function template(ctx, node, key = \\"\\") {
|
||||
let b2, b3;
|
||||
b2 = text(\`Main\`);
|
||||
if (ctx['state'].ok) {
|
||||
const Comp1 = ctx['component'];
|
||||
b3 = toggler(Comp1, comp1({}, (Comp1).name + key + \`__1\`, node, this, Comp1));
|
||||
}
|
||||
return multi([b2, b3]);
|
||||
}
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`can catch errors can catch an error in onmounted 3`] = `
|
||||
"function anonymous(app, bdom, helpers
|
||||
) {
|
||||
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||
|
||||
let block1 = createBlock(\`<div>Error!!!</div>\`);
|
||||
|
||||
return function template(ctx, node, key = \\"\\") {
|
||||
return block1();
|
||||
}
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`can catch errors can catch an error in onmounted 4`] = `
|
||||
"function anonymous(app, bdom, helpers
|
||||
) {
|
||||
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||
|
||||
let block1 = createBlock(\`<div>perfect</div>\`);
|
||||
|
||||
return function template(ctx, node, key = \\"\\") {
|
||||
return block1();
|
||||
}
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`can catch errors can catch an error in the constructor call of a component render function 1`] = `
|
||||
"function anonymous(app, bdom, helpers
|
||||
) {
|
||||
@@ -1191,135 +1147,6 @@ exports[`can catch errors error in mounted on a component with a sibling (proper
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`can catch errors error in onMounted, graceful recovery 1`] = `
|
||||
"function anonymous(app, bdom, helpers
|
||||
) {
|
||||
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||
const comp1 = app.createComponent(null, false, false, false, []);
|
||||
|
||||
return function template(ctx, node, key = \\"\\") {
|
||||
const Comp1 = ctx['component'];
|
||||
return toggler(Comp1, comp1({}, (Comp1).name + key + \`__1\`, node, this, Comp1));
|
||||
}
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`can catch errors error in onMounted, graceful recovery 2`] = `
|
||||
"function anonymous(app, bdom, helpers
|
||||
) {
|
||||
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||
const comp1 = app.createComponent(\`Child\`, true, false, false, []);
|
||||
const comp2 = app.createComponent(\`Boom\`, true, false, false, []);
|
||||
|
||||
return function template(ctx, node, key = \\"\\") {
|
||||
const b2 = text(\`parent\`);
|
||||
const b3 = comp1({}, key + \`__1\`, node, this, null);
|
||||
const b4 = comp2({}, key + \`__2\`, node, this, null);
|
||||
return multi([b2, b3, b4]);
|
||||
}
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`can catch errors error in onMounted, graceful recovery 3`] = `
|
||||
"function anonymous(app, bdom, helpers
|
||||
) {
|
||||
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||
|
||||
return function template(ctx, node, key = \\"\\") {
|
||||
return text(\`abc\`);
|
||||
}
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`can catch errors error in onMounted, graceful recovery 4`] = `
|
||||
"function anonymous(app, bdom, helpers
|
||||
) {
|
||||
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||
|
||||
return function template(ctx, node, key = \\"\\") {
|
||||
return text(\`boom\`);
|
||||
}
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`can catch errors error in onMounted, graceful recovery 5`] = `
|
||||
"function anonymous(app, bdom, helpers
|
||||
) {
|
||||
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||
|
||||
return function template(ctx, node, key = \\"\\") {
|
||||
return text(\`def\`);
|
||||
}
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`can catch errors error in onMounted, graceful recovery, variation 1`] = `
|
||||
"function anonymous(app, bdom, helpers
|
||||
) {
|
||||
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||
const comp1 = app.createComponent(null, false, false, false, []);
|
||||
|
||||
return function template(ctx, node, key = \\"\\") {
|
||||
let b2, b3;
|
||||
b2 = text(\`R\`);
|
||||
if (ctx['state'].gogogo) {
|
||||
const Comp1 = ctx['component'];
|
||||
b3 = toggler(Comp1, comp1({}, (Comp1).name + key + \`__1\`, node, this, Comp1));
|
||||
}
|
||||
return multi([b2, b3]);
|
||||
}
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`can catch errors error in onMounted, graceful recovery, variation 3`] = `
|
||||
"function anonymous(app, bdom, helpers
|
||||
) {
|
||||
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||
const comp1 = app.createComponent(\`Child\`, true, false, false, []);
|
||||
const comp2 = app.createComponent(\`Boom\`, true, false, false, []);
|
||||
|
||||
return function template(ctx, node, key = \\"\\") {
|
||||
const b2 = text(\`parent\`);
|
||||
const b3 = comp1({}, key + \`__1\`, node, this, null);
|
||||
const b4 = comp2({}, key + \`__2\`, node, this, null);
|
||||
return multi([b2, b3, b4]);
|
||||
}
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`can catch errors error in onMounted, graceful recovery, variation 4`] = `
|
||||
"function anonymous(app, bdom, helpers
|
||||
) {
|
||||
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||
|
||||
return function template(ctx, node, key = \\"\\") {
|
||||
return text(\`abc\`);
|
||||
}
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`can catch errors error in onMounted, graceful recovery, variation 5`] = `
|
||||
"function anonymous(app, bdom, helpers
|
||||
) {
|
||||
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||
|
||||
return function template(ctx, node, key = \\"\\") {
|
||||
return text(\`boom\`);
|
||||
}
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`can catch errors error in onMounted, graceful recovery, variation 6`] = `
|
||||
"function anonymous(app, bdom, helpers
|
||||
) {
|
||||
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||
|
||||
return function template(ctx, node, key = \\"\\") {
|
||||
return text(\`def\`);
|
||||
}
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`can catch errors onError in class inheritance is called if rethrown 1`] = `
|
||||
"function anonymous(app, bdom, helpers
|
||||
) {
|
||||
|
||||
@@ -332,6 +332,31 @@ exports[`lifecycle hooks lifecycle semantics, part 3 1`] = `
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`lifecycle hooks lifecycle semantics, part 3 3`] = `
|
||||
"function anonymous(app, bdom, helpers
|
||||
) {
|
||||
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||
const comp1 = app.createComponent(\`GrandChild\`, true, false, false, []);
|
||||
|
||||
return function template(ctx, node, key = \\"\\") {
|
||||
return comp1({}, key + \`__1\`, node, this, null);
|
||||
}
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`lifecycle hooks lifecycle semantics, part 3 4`] = `
|
||||
"function anonymous(app, bdom, helpers
|
||||
) {
|
||||
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||
|
||||
let block1 = createBlock(\`<div/>\`);
|
||||
|
||||
return function template(ctx, node, key = \\"\\") {
|
||||
return block1();
|
||||
}
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`lifecycle hooks lifecycle semantics, part 4 1`] = `
|
||||
"function anonymous(app, bdom, helpers
|
||||
) {
|
||||
|
||||
@@ -0,0 +1,258 @@
|
||||
import { Component, markup, mount, useState, xml } from "../../src";
|
||||
import { useAttachedEl } from "../../src/runtime/hooks";
|
||||
import { makeTestFixture, nextTick, steps, useLogLifecycle } from "../helpers";
|
||||
|
||||
let fixture: HTMLElement;
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = makeTestFixture();
|
||||
});
|
||||
|
||||
describe("basics", () => {
|
||||
test("can attach an empty component", async () => {
|
||||
fixture.innerHTML = "<div>hello</div>";
|
||||
|
||||
class Test extends Component {
|
||||
setup() {
|
||||
useLogLifecycle();
|
||||
}
|
||||
}
|
||||
|
||||
await mount(Test, fixture, { position: "attach" });
|
||||
expect(steps.splice(0)).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
"Test:setup",
|
||||
"Test:willStart",
|
||||
"Test:willRender",
|
||||
"Test:rendered",
|
||||
"Test:mounted",
|
||||
]
|
||||
`);
|
||||
expect(fixture.innerHTML).toBe("<div>hello</div>");
|
||||
});
|
||||
|
||||
test("attaching a component with a template throws", async () => {
|
||||
fixture.innerHTML = "<div>hello</div>";
|
||||
|
||||
class Test extends Component {
|
||||
static template = xml`hello`;
|
||||
}
|
||||
|
||||
let error: Error | null = null;
|
||||
try {
|
||||
await mount(Test, fixture, { position: "attach" });
|
||||
} catch (e: any) {
|
||||
error = e;
|
||||
}
|
||||
expect(error!.message).toBe("Cannot attach a component with a template");
|
||||
|
||||
expect(fixture.innerHTML).toBe("<div>hello</div>");
|
||||
});
|
||||
|
||||
test("can attach a component with simple dynamic content", async () => {
|
||||
fixture.innerHTML = "<div><p>hello</p></div>";
|
||||
|
||||
class Test extends Component {
|
||||
static dynamicContent = {
|
||||
"p:t-att-a": "value",
|
||||
};
|
||||
value: string = "";
|
||||
setup() {
|
||||
this.value = "b";
|
||||
}
|
||||
}
|
||||
|
||||
await mount(Test, fixture, { position: "attach" });
|
||||
expect(fixture.innerHTML).toBe('<div><p a="b">hello</p></div>');
|
||||
});
|
||||
|
||||
test("useAttachedEl returns the attached element", async () => {
|
||||
fixture.innerHTML = "<div><p>hello</p></div>";
|
||||
let el: any = null;
|
||||
|
||||
class Test extends Component {
|
||||
setup() {
|
||||
el = useAttachedEl();
|
||||
}
|
||||
}
|
||||
|
||||
await mount(Test, fixture, { position: "attach" });
|
||||
expect(el).toBe(fixture);
|
||||
});
|
||||
|
||||
test("useAttachedEl throws if component is not attached", async () => {
|
||||
class Test extends Component {
|
||||
static template = xml`hello`;
|
||||
setup() {
|
||||
useAttachedEl();
|
||||
}
|
||||
}
|
||||
|
||||
let error: any = null;
|
||||
try {
|
||||
await mount(Test, fixture);
|
||||
} catch (_e: any) {
|
||||
error = _e;
|
||||
}
|
||||
|
||||
expect(error.message).toBe("useAttachedEl can only be called with component that are attached");
|
||||
});
|
||||
|
||||
test("multiple dynamic attribute", async () => {
|
||||
fixture.innerHTML = "<div><p>hello</p></div>";
|
||||
|
||||
class Test extends Component {
|
||||
static dynamicContent = {
|
||||
"p:t-att-a": "value",
|
||||
"p:t-att-b": "value + 'coucou'",
|
||||
};
|
||||
value: string = "";
|
||||
setup() {
|
||||
this.value = "b";
|
||||
}
|
||||
}
|
||||
|
||||
await mount(Test, fixture, { position: "attach" });
|
||||
expect(fixture.innerHTML).toBe('<div><p a="b" b="bcoucou">hello</p></div>');
|
||||
});
|
||||
|
||||
test("attrs can target root", async () => {
|
||||
fixture.innerHTML = "<p>hello</p>";
|
||||
|
||||
class Test extends Component {
|
||||
static dynamicContent = {
|
||||
"root:t-att-a": "value",
|
||||
};
|
||||
value: string = "";
|
||||
setup() {
|
||||
this.value = "b";
|
||||
}
|
||||
}
|
||||
|
||||
await mount(Test, fixture, { position: "attach" });
|
||||
expect(fixture.outerHTML).toBe('<div a="b"><p>hello</p></div>');
|
||||
});
|
||||
|
||||
test("dynamic attribute is updated on rerender", async () => {
|
||||
fixture.innerHTML = "<div><p>hello</p></div>";
|
||||
|
||||
class Test extends Component {
|
||||
static dynamicContent = {
|
||||
"p:t-att-a": "state.value",
|
||||
};
|
||||
state: any;
|
||||
setup() {
|
||||
this.state = useState({ value: 1 });
|
||||
}
|
||||
}
|
||||
|
||||
const test = await mount(Test, fixture, { position: "attach" });
|
||||
expect(fixture.innerHTML).toBe('<div><p a="1">hello</p></div>');
|
||||
test.state.value = 2;
|
||||
await nextTick();
|
||||
expect(fixture.innerHTML).toBe('<div><p a="2">hello</p></div>');
|
||||
});
|
||||
|
||||
test("t-on-click, basic", async () => {
|
||||
fixture.innerHTML = "<div><p>hello</p></div>";
|
||||
|
||||
let ev: Event | null = null;
|
||||
|
||||
class Test extends Component {
|
||||
static dynamicContent = {
|
||||
"p:t-att-a": "state.value",
|
||||
"p:t-on-click": "onClick",
|
||||
};
|
||||
state: any;
|
||||
setup() {
|
||||
this.state = useState({ value: 1 });
|
||||
}
|
||||
onClick(_ev: any) {
|
||||
ev = _ev;
|
||||
this.state.value = 2;
|
||||
}
|
||||
}
|
||||
|
||||
await mount(Test, fixture, { position: "attach" });
|
||||
expect(fixture.innerHTML).toBe('<div><p a="1">hello</p></div>');
|
||||
fixture.querySelector("p")!.click();
|
||||
expect(ev).toBeInstanceOf(Event);
|
||||
await nextTick();
|
||||
expect(fixture.innerHTML).toBe('<div><p a="2">hello</p></div>');
|
||||
});
|
||||
|
||||
test("t-on-click, target root element", async () => {
|
||||
fixture.innerHTML = "hello";
|
||||
let click = false;
|
||||
class Test extends Component {
|
||||
static dynamicContent = {
|
||||
"root:t-on-click": "onClick",
|
||||
};
|
||||
onClick() {
|
||||
click = true;
|
||||
}
|
||||
}
|
||||
|
||||
await mount(Test, fixture, { position: "attach" });
|
||||
fixture.click();
|
||||
expect(click).toBe(true);
|
||||
});
|
||||
|
||||
test("t-out, basic", async () => {
|
||||
fixture.innerHTML = "<div><p>hello</p></div>";
|
||||
|
||||
class Test extends Component {
|
||||
static dynamicContent = {
|
||||
"p:t-out": "state.value",
|
||||
};
|
||||
state: any;
|
||||
setup() {
|
||||
this.state = useState({ value: 1 });
|
||||
}
|
||||
}
|
||||
|
||||
await mount(Test, fixture, { position: "attach" });
|
||||
expect(fixture.innerHTML).toBe("<div><p>1</p></div>");
|
||||
});
|
||||
|
||||
test("t-out, on root", async () => {
|
||||
fixture.innerHTML = "hello";
|
||||
|
||||
class Test extends Component {
|
||||
static dynamicContent = {
|
||||
"root:t-out": "state.value",
|
||||
};
|
||||
state: any;
|
||||
setup() {
|
||||
this.state = useState({ value: 1 });
|
||||
}
|
||||
}
|
||||
|
||||
expect(fixture.outerHTML).toBe("<div>hello</div>");
|
||||
await mount(Test, fixture, { position: "attach" });
|
||||
expect(fixture.outerHTML).toBe("<div>1</div>");
|
||||
});
|
||||
|
||||
test("t-out, with markup", async () => {
|
||||
fixture.innerHTML = `<p class="p1">hello</p><p class="p2">hello</p>`;
|
||||
|
||||
class Test extends Component {
|
||||
static dynamicContent = {
|
||||
"p.p1:t-out": "value1",
|
||||
"p.p2:t-out": "value2",
|
||||
};
|
||||
|
||||
value1: any;
|
||||
value2: any;
|
||||
setup() {
|
||||
this.value1 = "<div>value1</div>";
|
||||
this.value2 = markup("<div>value2</div>");
|
||||
}
|
||||
}
|
||||
|
||||
await mount(Test, fixture, { position: "attach" });
|
||||
expect(fixture.innerHTML).toBe(
|
||||
`<p class="p1"><div>value1</div></p><p class="p2"><div>value2</div></p>`
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -564,82 +564,6 @@ describe("can catch errors", () => {
|
||||
expect(mockConsoleWarn).toBeCalledTimes(0);
|
||||
});
|
||||
|
||||
test("can catch an error in onmounted", async () => {
|
||||
class ErrorComponent extends Component {
|
||||
static template = xml`<div>Error!!!</div>`;
|
||||
setup() {
|
||||
useLogLifecycle();
|
||||
onMounted(() => {
|
||||
throw new Error("error");
|
||||
});
|
||||
}
|
||||
}
|
||||
class PerfectComponent extends Component {
|
||||
static template = xml`<div>perfect</div>`;
|
||||
setup() {
|
||||
useLogLifecycle();
|
||||
}
|
||||
}
|
||||
class Main extends Component {
|
||||
static template = xml`Main<t t-if="state.ok" t-component="component"/>`;
|
||||
component: any;
|
||||
state: any;
|
||||
setup() {
|
||||
this.state = useState({ ok: false });
|
||||
useLogLifecycle();
|
||||
this.component = ErrorComponent;
|
||||
onError(() => {
|
||||
this.component = PerfectComponent;
|
||||
this.render();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const app = await mount(Main, fixture);
|
||||
expect(steps.splice(0)).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
"Main:setup",
|
||||
"Main:willStart",
|
||||
"Main:willRender",
|
||||
"Main:rendered",
|
||||
"Main:mounted",
|
||||
]
|
||||
`);
|
||||
expect(fixture.innerHTML).toBe("Main");
|
||||
(app as any).state.ok = true;
|
||||
await nextTick();
|
||||
expect(fixture.innerHTML).toBe("Main<div>Error!!!</div>");
|
||||
expect(steps.splice(0)).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
"Main:willRender",
|
||||
"ErrorComponent:setup",
|
||||
"ErrorComponent:willStart",
|
||||
"Main:rendered",
|
||||
"ErrorComponent:willRender",
|
||||
"ErrorComponent:rendered",
|
||||
"Main:willPatch",
|
||||
"ErrorComponent:mounted",
|
||||
"Main:willRender",
|
||||
"PerfectComponent:setup",
|
||||
"PerfectComponent:willStart",
|
||||
"Main:rendered",
|
||||
]
|
||||
`);
|
||||
await nextTick();
|
||||
expect(steps.splice(0)).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
"PerfectComponent:willRender",
|
||||
"PerfectComponent:rendered",
|
||||
"Main:willPatch",
|
||||
"ErrorComponent:willUnmount",
|
||||
"ErrorComponent:willDestroy",
|
||||
"PerfectComponent:mounted",
|
||||
"Main:patched",
|
||||
]
|
||||
`);
|
||||
expect(fixture.innerHTML).toBe("Main<div>perfect</div>");
|
||||
});
|
||||
|
||||
test("calling a hook outside setup should crash", async () => {
|
||||
class Root extends Component {
|
||||
static template = xml`<t t-esc="state.value"/>`;
|
||||
@@ -1678,198 +1602,4 @@ describe("can catch errors", () => {
|
||||
`);
|
||||
expect(fixture.innerHTML).toBe("2");
|
||||
});
|
||||
|
||||
test("error in onMounted, graceful recovery", async () => {
|
||||
class Child extends Component {
|
||||
static template = xml`abc`;
|
||||
setup() {
|
||||
useLogLifecycle();
|
||||
}
|
||||
}
|
||||
|
||||
class OtherChild extends Component {
|
||||
static template = xml`def`;
|
||||
setup() {
|
||||
useLogLifecycle();
|
||||
}
|
||||
}
|
||||
|
||||
class Boom extends Component {
|
||||
static template = xml`boom`;
|
||||
setup() {
|
||||
useLogLifecycle();
|
||||
onMounted(() => {
|
||||
throw new Error("boom");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class Parent extends Component {
|
||||
static template = xml`parent<Child/><Boom/>`;
|
||||
static components = { Child, Boom };
|
||||
setup() {
|
||||
useLogLifecycle();
|
||||
}
|
||||
}
|
||||
|
||||
class Root extends Component {
|
||||
static template = xml`<t t-component="component"/>`;
|
||||
|
||||
component: any = Parent;
|
||||
setup() {
|
||||
useLogLifecycle();
|
||||
onError(() => {
|
||||
logStep("error");
|
||||
this.component = OtherChild;
|
||||
this.render();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
await mount(Root, fixture);
|
||||
expect(fixture.innerHTML).toBe("def");
|
||||
|
||||
expect(steps.splice(0)).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
"Root:setup",
|
||||
"Root:willStart",
|
||||
"Root:willRender",
|
||||
"Parent:setup",
|
||||
"Parent:willStart",
|
||||
"Root:rendered",
|
||||
"Parent:willRender",
|
||||
"Child:setup",
|
||||
"Child:willStart",
|
||||
"Boom:setup",
|
||||
"Boom:willStart",
|
||||
"Parent:rendered",
|
||||
"Child:willRender",
|
||||
"Child:rendered",
|
||||
"Boom:willRender",
|
||||
"Boom:rendered",
|
||||
"Boom:mounted",
|
||||
"error",
|
||||
"Root:willRender",
|
||||
"OtherChild:setup",
|
||||
"OtherChild:willStart",
|
||||
"Root:rendered",
|
||||
"OtherChild:willRender",
|
||||
"OtherChild:rendered",
|
||||
"OtherChild:mounted",
|
||||
"Root:mounted",
|
||||
]
|
||||
`);
|
||||
});
|
||||
|
||||
test("error in onMounted, graceful recovery, variation", async () => {
|
||||
class Child extends Component {
|
||||
static template = xml`abc`;
|
||||
setup() {
|
||||
useLogLifecycle();
|
||||
}
|
||||
}
|
||||
|
||||
class OtherChild extends Component {
|
||||
static template = xml`def`;
|
||||
setup() {
|
||||
useLogLifecycle();
|
||||
}
|
||||
}
|
||||
|
||||
class Boom extends Component {
|
||||
static template = xml`boom`;
|
||||
setup() {
|
||||
useLogLifecycle();
|
||||
onMounted(() => {
|
||||
throw new Error("boom");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class Parent extends Component {
|
||||
static template = xml`parent<Child/><Boom/>`;
|
||||
static components = { Child, Boom };
|
||||
setup() {
|
||||
useLogLifecycle();
|
||||
}
|
||||
}
|
||||
|
||||
class Root extends Component {
|
||||
static template = xml`R<t t-if="state.gogogo" t-component="component"/>`;
|
||||
|
||||
component: any = Parent;
|
||||
state = useState({ gogogo: false });
|
||||
|
||||
setup() {
|
||||
useLogLifecycle();
|
||||
onError(() => {
|
||||
logStep("error");
|
||||
this.component = OtherChild;
|
||||
this.render();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const root = await mount(Root, fixture);
|
||||
expect(fixture.innerHTML).toBe("R");
|
||||
|
||||
// standard mounting process
|
||||
expect(steps.splice(0)).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
"Root:setup",
|
||||
"Root:willStart",
|
||||
"Root:willRender",
|
||||
"Root:rendered",
|
||||
"Root:mounted",
|
||||
]
|
||||
`);
|
||||
|
||||
root.state.gogogo = true;
|
||||
await nextTick();
|
||||
|
||||
expect(fixture.innerHTML).toBe("Rparentabcboom");
|
||||
// rerender, root creates sub components, it crashes, tries to recover
|
||||
expect(steps.splice(0)).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
"Root:willRender",
|
||||
"Parent:setup",
|
||||
"Parent:willStart",
|
||||
"Root:rendered",
|
||||
"Parent:willRender",
|
||||
"Child:setup",
|
||||
"Child:willStart",
|
||||
"Boom:setup",
|
||||
"Boom:willStart",
|
||||
"Parent:rendered",
|
||||
"Child:willRender",
|
||||
"Child:rendered",
|
||||
"Boom:willRender",
|
||||
"Boom:rendered",
|
||||
"Root:willPatch",
|
||||
"Boom:mounted",
|
||||
"error",
|
||||
"Root:willRender",
|
||||
"OtherChild:setup",
|
||||
"OtherChild:willStart",
|
||||
"Root:rendered",
|
||||
]
|
||||
`);
|
||||
|
||||
await nextTick();
|
||||
expect(fixture.innerHTML).toBe("Rdef");
|
||||
|
||||
expect(steps.splice(0)).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
"OtherChild:willRender",
|
||||
"OtherChild:rendered",
|
||||
"Root:willPatch",
|
||||
"Child:willDestroy",
|
||||
"Boom:willUnmount",
|
||||
"Boom:willDestroy",
|
||||
"Parent:willDestroy",
|
||||
"OtherChild:mounted",
|
||||
"Root:patched",
|
||||
]
|
||||
`);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -339,7 +339,7 @@ test("throw if prop uses an unknown suffix", async () => {
|
||||
|
||||
await expect(async () => {
|
||||
await mount(Parent, fixture);
|
||||
}).rejects.toThrowError("Invalid prop suffix: somesuffix");
|
||||
}).rejects.toThrowError("Invalid prop suffix");
|
||||
});
|
||||
|
||||
test(".alike suffix in a simple case", async () => {
|
||||
|
||||
@@ -702,7 +702,7 @@ describe("props validation", () => {
|
||||
const app = new App(Parent, { test: true });
|
||||
await app.mount(fixture);
|
||||
expect(fixture.innerHTML).toBe("12");
|
||||
expect(app.root!.subscriptions).toEqual([{ keys: ["otherValue"], target: obj }]);
|
||||
expect(app.root!.node!.subscriptions).toEqual([{ keys: ["otherValue"], target: obj }]);
|
||||
});
|
||||
|
||||
test("props are validated whenever component is updated", async () => {
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
// this is the "compile_owl_templates" command that owl makes available when
|
||||
// installed as a node_module.
|
||||
import { existsSync, mkdirSync, writeFileSync } from "fs";
|
||||
import { dirname } from "path";
|
||||
import { compileTemplates } from "../dist/compile_templates.mjs";
|
||||
import { parseArgs } from "util";
|
||||
|
||||
const { values, positionals } = parseArgs({
|
||||
allowPositionals: true,
|
||||
options: {
|
||||
output: {
|
||||
type: "string",
|
||||
short: "o",
|
||||
default: "templates.js",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (positionals.length) {
|
||||
const result = await compileTemplates(positionals);
|
||||
const outputPath = values.output;
|
||||
const dir = dirname(outputPath);
|
||||
if (!existsSync(dir)) {
|
||||
mkdirSync(dir, { recursive: true });
|
||||
}
|
||||
writeFileSync(outputPath, result);
|
||||
} else {
|
||||
console.log("Please provide a path");
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const jsdom = require("jsdom");
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// add global DOM stuff for compiler
|
||||
// -----------------------------------------------------------------------------
|
||||
var document = new jsdom.JSDOM("", {});
|
||||
var window = document.window;
|
||||
global.document = window.document;
|
||||
global.window = window;
|
||||
global.DOMParser = window.DOMParser;
|
||||
global.Element = window.Element;
|
||||
global.Node = window.Node;
|
||||
// this needs to be below the jsdom stuff
|
||||
const { compile } = require("../dist/compiler.js");
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// helpers
|
||||
// -----------------------------------------------------------------------------
|
||||
async function getXmlFiles(dir) {
|
||||
let xmls = [];
|
||||
const files = await fs.promises.readdir(dir);
|
||||
const filesStats = await Promise.all(files.map((file) => fs.promises.stat(path.join(dir, file))));
|
||||
for (let i in files) {
|
||||
const name = path.join(dir, files[i]);
|
||||
if (filesStats[i].isDirectory()) {
|
||||
xmls = xmls.concat(await getXmlFiles(name));
|
||||
} else {
|
||||
if (name.endsWith(".xml")) {
|
||||
xmls.push(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
return xmls;
|
||||
}
|
||||
|
||||
function writeToFile(filepath, data) {
|
||||
if (!fs.existsSync(path.dirname(filepath))) {
|
||||
fs.mkdirSync(path.dirname(filepath), { recursive: true });
|
||||
}
|
||||
fs.writeFile(filepath, data, (err) => {
|
||||
if (err) {
|
||||
process.stdout.write(`Error while writing file ${filepath}: ${err}`);
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// adapted from https://medium.com/@mhagemann/the-ultimate-way-to-slugify-a-url-string-in-javascript-b8e4a0d849e1
|
||||
const a = "·-_,:;";
|
||||
const p = new RegExp(a.split("").join("|"), "g");
|
||||
|
||||
function slugify(str) {
|
||||
return str
|
||||
.replace(/\//g, "") // remove /
|
||||
.replace(/\./g, "_") // Replace . with _
|
||||
.replace(p, (c) => '_') // Replace special characters
|
||||
.replace(/&/g, "_and_") // Replace & with ‘and’
|
||||
.replace(/[^\w\-]+/g, "") // Remove all non-word characters
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// main
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
async function compileTemplates(files) {
|
||||
process.stdout.write(`Processing ${files.length} files`);
|
||||
let xmlStrings = await Promise.all(files.map((file) => fs.promises.readFile(file, "utf8")));
|
||||
|
||||
const templates = [];
|
||||
const errors = [];
|
||||
|
||||
for (let i = 0; i < files.length; i++) {
|
||||
const fileName = files[i];
|
||||
const fileContent = xmlStrings[i];
|
||||
process.stdout.write(`.`);
|
||||
const parser = new DOMParser();
|
||||
const doc = parser.parseFromString(fileContent, "text/xml");
|
||||
for (const template of doc.querySelectorAll("[t-name]")) {
|
||||
const name = template.getAttribute("t-name");
|
||||
if (template.hasAttribute("owl")) {
|
||||
template.removeAttribute("owl")
|
||||
}
|
||||
const fnName = slugify(name);
|
||||
try {
|
||||
const fn = compile(template).toString().replace('anonymous', fnName);
|
||||
templates.push(`"${name}": ${fn},\n`);
|
||||
} catch (e) {
|
||||
errors.push({ name, fileName, e });
|
||||
}
|
||||
}
|
||||
}
|
||||
process.stdout.write(`\n`);
|
||||
|
||||
for (let { name, fileName, e } of errors) {
|
||||
console.warn(`Error while compiling '${name}' (in file ${fileName})`);
|
||||
console.error(e);
|
||||
}
|
||||
console.log(`${templates.length} templates compiled`);
|
||||
|
||||
return `export const templates = {\n ${templates.join("\n")} \n}`;
|
||||
}
|
||||
|
||||
const templatesPath = process.argv[2];
|
||||
if (templatesPath && templatesPath.length) {
|
||||
getXmlFiles(templatesPath).then(async (files) => {
|
||||
const result = await compileTemplates(files);
|
||||
writeToFile("templates.js", result);
|
||||
});
|
||||
} else {
|
||||
console.log("Please provide a path");
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "Owl devtools",
|
||||
"version": "1.3.0",
|
||||
"version": "1.2.2",
|
||||
"manifest_version": 3,
|
||||
"description": "Chrome devtools extension for Odoo Owl framework",
|
||||
"icons": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "Owl devtools",
|
||||
"version": "1.1.0",
|
||||
"version": "1.0.0",
|
||||
"description": "Firefox devtools extension for Odoo Owl framework",
|
||||
"manifest_version": 2,
|
||||
"browser_specific_settings": {
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
import { useStore } from "../store/store";
|
||||
|
||||
const { Component, useEffect, useRef } = owl;
|
||||
|
||||
export class ContextMenu extends Component {
|
||||
static template = "devtools.ContextMenu";
|
||||
static props = {
|
||||
items: Array,
|
||||
};
|
||||
setup() {
|
||||
this.store = useStore();
|
||||
this.contextMenu = useRef("contextmenu");
|
||||
useEffect(
|
||||
(position) => {
|
||||
const menu = this.contextMenu.el;
|
||||
const menuWidth = menu.offsetWidth;
|
||||
const menuHeight = menu.offsetHeight;
|
||||
let { x, y } = position;
|
||||
if (x + menuWidth > window.innerWidth) {
|
||||
x = window.innerWidth - menuWidth;
|
||||
}
|
||||
if (y + menuHeight > window.innerHeight) {
|
||||
y = window.innerHeight - menuHeight;
|
||||
}
|
||||
menu.style.left = x + "px";
|
||||
// Need 25px offset because of the main navbar from the browser devtools
|
||||
menu.style.top = y + "px";
|
||||
},
|
||||
() => [this.store.contextMenu?.position]
|
||||
);
|
||||
}
|
||||
onClickItem(action) {
|
||||
action();
|
||||
this.store.contextMenu = null;
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<templates xml:space="preserve">
|
||||
<t t-name="devtools.ContextMenu">
|
||||
<div class="custom-menu" t-ref="contextmenu">
|
||||
<ul class="my-1">
|
||||
<li t-foreach="props.items" t-as="item" t-key="item_index" t-if="item.show" t-esc="item.title" t-on-click.stop="() => this.onClickItem(item.action)" class="custom-menu-item py-1 px-4"/>
|
||||
</ul>
|
||||
</div>
|
||||
</t>
|
||||
</templates>
|
||||
@@ -1,4 +1,4 @@
|
||||
const { Component } = owl;
|
||||
const { Component, useRef, useEffect } = owl;
|
||||
import { useStore } from "../../../store/store";
|
||||
import { ObjectTreeElement } from "./object_tree_element/object_tree_element";
|
||||
|
||||
@@ -7,64 +7,23 @@ export class DetailsWindow extends Component {
|
||||
static components = { ObjectTreeElement };
|
||||
setup() {
|
||||
this.store = useStore();
|
||||
}
|
||||
|
||||
get contextMenuItems() {
|
||||
return [
|
||||
{
|
||||
title: "Inspect source code",
|
||||
show: true,
|
||||
action: () => this.store.inspectComponent("source", this.store.activeComponent.path),
|
||||
this.contextMenu = useRef("contextmenu");
|
||||
this.contextMenuId = this.store.contextMenu.id++;
|
||||
this.contextMenuEvent;
|
||||
// Open the context menu when the ids match
|
||||
useEffect(
|
||||
(menuId) => {
|
||||
if (menuId === this.contextMenuId) {
|
||||
this.store.contextMenu.open(this.contextMenuEvent, this.contextMenu.el);
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "Store as global variable",
|
||||
show: this.store.activeComponent.path.length !== 1,
|
||||
action: () =>
|
||||
this.store.logObjectInConsole([
|
||||
...this.store.activeComponent.path,
|
||||
{ type: "item", value: "component" },
|
||||
]),
|
||||
},
|
||||
{
|
||||
title: "Inspect in Elements tab",
|
||||
show: this.store.activeComponent.path.length !== 1,
|
||||
action: () => this.store.inspectComponent("DOM", this.store.activeComponent.path),
|
||||
},
|
||||
{
|
||||
title: "Force rerender",
|
||||
show: this.store.activeComponent.path.length !== 1,
|
||||
action: () => this.store.refreshComponent(this.store.activeComponent.path),
|
||||
},
|
||||
{
|
||||
title: "Store observed states as global variable",
|
||||
show: this.store.activeComponent.path.length !== 1,
|
||||
action: () =>
|
||||
this.store.logObjectInConsole([
|
||||
...this.store.activeComponent.path,
|
||||
{ type: "item", value: "subscriptions" },
|
||||
]),
|
||||
},
|
||||
{
|
||||
title: "Inspect compiled template",
|
||||
show: this.store.activeComponent.path.length !== 1,
|
||||
action: () =>
|
||||
this.store.inspectComponent("compiled template", this.store.activeComponent.path),
|
||||
},
|
||||
{
|
||||
title: "Log raw template",
|
||||
show: this.store.activeComponent.path.length !== 1,
|
||||
action: () => this.store.inspectComponent("raw template", this.store.activeComponent.path),
|
||||
},
|
||||
{
|
||||
title: "Store as global variable",
|
||||
show: this.store.activeComponent.path.length === 1,
|
||||
action: () => this.store.logObjectInConsole([...this.store.activeComponent.path]),
|
||||
},
|
||||
];
|
||||
() => [this.store.contextMenu.activeMenu]
|
||||
);
|
||||
}
|
||||
|
||||
openMenu(ev) {
|
||||
this.store.openContextMenu(ev, this.contextMenuItems);
|
||||
this.contextMenuEvent = ev;
|
||||
this.store.contextMenu.activeMenu = this.contextMenuId;
|
||||
}
|
||||
|
||||
toggleCategory(ev, category) {
|
||||
|
||||
@@ -20,17 +20,6 @@
|
||||
</t>
|
||||
</div>
|
||||
<div class="details-container">
|
||||
<div t-if="store.observedVariables.length and store.observedVariables.some((v) => v.visible)" id="observedVariables" class="details-panel ps-2 py-1">
|
||||
<div class="d-flex mb-2">
|
||||
<div class="w-100">
|
||||
<b class="ps-2">observed variables</b>
|
||||
</div>
|
||||
<i title="Remove observed variables" class="fa fa-times utility-icon p-1" t-on-click.stop="() => this.store.clearObservedVariable()"></i>
|
||||
</div>
|
||||
<t t-foreach="store.observedVariables" t-as="observed" t-key="observed_index" t-if="observed.visible">
|
||||
<ObjectTreeElement object="observed" index="observed_index"/>
|
||||
</t>
|
||||
</div>
|
||||
<div t-if="store.activeComponent.env.children.length > 0" id="env" class="details-panel ps-2 py-1">
|
||||
<div class="d-flex mb-2">
|
||||
<div class="w-100" t-on-click.stop="(ev) => this.toggleCategory(ev, 'env')">
|
||||
@@ -70,7 +59,7 @@
|
||||
</t>
|
||||
</div>
|
||||
</div>
|
||||
<div t-if="store.activeComponent.instance.children.length > 0" id="instance" class="details-panel ps-2 py-1">
|
||||
<div t-if="store.activeComponent.instance.children.length > 0" id="instance" class="details-panel ps-2 py-1">
|
||||
<div class="d-flex mb-2">
|
||||
<div class="w-100 text-truncate" t-on-click.stop="(ev) => this.toggleCategory(ev, 'instance')">
|
||||
<i class="fa mx-1 pointer-icon"
|
||||
@@ -86,19 +75,22 @@
|
||||
<ObjectTreeElement object="instance"/>
|
||||
</t>
|
||||
</div>
|
||||
<div t-if="store.activeComponent.hooks?.children.length > 0" id="hooks" class="details-panel ps-2 py-1">
|
||||
<div class="d-flex mb-2">
|
||||
<div class="w-100" t-on-click.stop="(ev) => this.toggleCategory(ev, 'hooks')">
|
||||
<i class="fa mx-1 pointer-icon"
|
||||
t-att-class="{'fa-caret-right': !store.activeComponent.hooks.toggled, 'fa-caret-down': store.activeComponent.hooks.toggled}"
|
||||
/><b>hooks</b>
|
||||
</div>
|
||||
<i title="Remove breakpoints" class="fa fa-times utility-icon p-1" t-on-click.stop="() => this.store.removeBreakpoints()"></i>
|
||||
</div>
|
||||
<t t-if="store.activeComponent.hooks.toggled" t-foreach="store.activeComponent.hooks.children" t-as="hook" t-key="hook_index">
|
||||
<ObjectTreeElement object="hook"/>
|
||||
</div>
|
||||
<div t-if="store.contextMenu.activeMenu === contextMenuId" class="custom-menu" t-ref="contextmenu">
|
||||
<ul class="my-1">
|
||||
<li t-on-click.stop="() => this.store.inspectComponent('source', store.activeComponent.path)" class="custom-menu-item py-1 px-4">Inspect source code</li>
|
||||
<t t-if="store.activeComponent.path.length !== 1">
|
||||
<li t-on-click.stop="() => this.store.logObjectInConsole([...store.activeComponent.path, { type: 'item', value: 'component'}])" class="custom-menu-item py-1 px-4">Store as global variable</li>
|
||||
<li t-on-click.stop="() => this.store.inspectComponent('DOM', store.activeComponent.path)" class="custom-menu-item py-1 px-4">Inspect in Elements tab</li>
|
||||
<li t-on-click.stop="() => this.store.refreshComponent(store.activeComponent.path)" class="custom-menu-item py-1 px-4">Force rerender</li>
|
||||
<li t-on-click.stop="() => this.store.logObjectInConsole([...store.activeComponent.path, { type: 'item', value: 'subscriptions'}])" class="custom-menu-item py-1 px-4">Store observed states as global variable</li>
|
||||
<li t-on-click.stop="() => this.store.inspectComponent('compiled template', store.activeComponent.path)" class="custom-menu-item py-1 px-4">Inspect compiled template</li>
|
||||
<li t-on-click.stop="() => this.store.inspectComponent('raw template', store.activeComponent.path)" class="custom-menu-item py-1 px-4">Log raw template</li>
|
||||
</t>
|
||||
</div>
|
||||
<t t-else="">
|
||||
<li t-on-click.stop="() => this.store.logObjectInConsole([...store.activeComponent.path])" class="custom-menu-item py-1 px-4">Store as global variable</li>
|
||||
</t>
|
||||
</ul>
|
||||
</div>
|
||||
</t>
|
||||
</templates>
|
||||
</templates>
|
||||
@@ -13,8 +13,19 @@ export class ObjectTreeElement extends Component {
|
||||
menuTop: 0,
|
||||
menuLeft: 0,
|
||||
});
|
||||
this.contextMenu = useRef("contextmenu");
|
||||
const inputRef = useRef("input");
|
||||
this.store = useStore();
|
||||
this.contextMenuId = this.store.contextMenu.id++;
|
||||
this.contextMenuEvent,
|
||||
useEffect(
|
||||
(menuId) => {
|
||||
if (menuId === this.contextMenuId) {
|
||||
this.store.contextMenu.open(this.contextMenuEvent, this.contextMenu.el);
|
||||
}
|
||||
},
|
||||
() => [this.store.contextMenu.activeMenu]
|
||||
);
|
||||
useEffect(
|
||||
(editMode) => {
|
||||
// Focus on the input when it is created
|
||||
@@ -52,76 +63,16 @@ export class ObjectTreeElement extends Component {
|
||||
return this.props.object.depth * 0.8 + 0.3;
|
||||
}
|
||||
|
||||
get contextMenuItems() {
|
||||
return [
|
||||
{
|
||||
title: "Store as global variable",
|
||||
show: true,
|
||||
action: () => this.store.logObjectInConsole(this.props.object.path),
|
||||
},
|
||||
{
|
||||
title: "Inspect function source code",
|
||||
show: this.props.object.contentType === "function",
|
||||
action: () => this.store.inspectFunctionSource(this.props.object.path),
|
||||
},
|
||||
{
|
||||
title: "Observe variable",
|
||||
show: this.props.object.objectType !== "observed",
|
||||
action: () => this.store.observeVariable(this.props.object.path),
|
||||
},
|
||||
{
|
||||
title: "Unobserve variable",
|
||||
show: this.props.object.objectType === "observed",
|
||||
action: () => this.store.clearObservedVariable(this.props.index),
|
||||
},
|
||||
{
|
||||
title: "Inject breakpoint on component",
|
||||
show: this.props.object.contentType === "array" && this.props.object.objectType === "hook",
|
||||
action: () =>
|
||||
this.store.injectBreakpoint(this.props.object.name, this.store.activeComponent.path),
|
||||
},
|
||||
{
|
||||
title: "Inject conditional breakpoint on component",
|
||||
show: this.props.object.contentType === "array" && this.props.object.objectType === "hook",
|
||||
action: () => {
|
||||
const condition = window.prompt("Enter the condition");
|
||||
if (condition) {
|
||||
this.store.injectBreakpoint(
|
||||
this.props.object.name,
|
||||
this.store.activeComponent.path,
|
||||
false,
|
||||
condition
|
||||
);
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Inject breakpoint on instance",
|
||||
show:
|
||||
this.props.object.contentType === "array" &&
|
||||
this.props.object.objectType === "hook" &&
|
||||
!["mounted", "willStart"].includes(this.props.object.name),
|
||||
action: () =>
|
||||
this.store.injectBreakpoint(
|
||||
this.props.object.name,
|
||||
this.store.activeComponent.path,
|
||||
true
|
||||
),
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
openMenu(ev) {
|
||||
this.store.openContextMenu(ev, this.contextMenuItems);
|
||||
this.contextMenuEvent = ev;
|
||||
this.store.contextMenu.activeMenu = this.contextMenuId;
|
||||
}
|
||||
|
||||
setupEditMode() {
|
||||
if (
|
||||
!this.state.editMode &&
|
||||
!this.props.object.hasChildren &&
|
||||
!(this.props.object.objectType === "observed")
|
||||
) {
|
||||
this.state.editMode = true;
|
||||
if (!this.state.editMode) {
|
||||
if (!this.props.object.hasChildren) {
|
||||
this.state.editMode = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<div class="m-0 p-0 text-nowrap w-100 object-line"
|
||||
t-att-class="props.class + (props.object.hasChildren ? ' bg-feedback' : '')"
|
||||
t-on-click.stop="() => this.store.toggleObjectTreeElementsDisplay(this.props.object)"
|
||||
t-on-contextmenu.prevent="openMenu"
|
||||
t-on-contextmenu.prevent="openMenu"
|
||||
>
|
||||
<div t-attf-style="padding-left: {{objectPadding}}rem">
|
||||
<i class="fa px-1 pointer-icon caret"
|
||||
@@ -12,7 +12,7 @@
|
||||
t-attf-style="visibility: {{props.object.hasChildren ? '' : 'hidden'}};"
|
||||
/>
|
||||
<t t-esc="props.object.name"/>
|
||||
<t t-if="props.object.content.length > 0">: </t>
|
||||
<t t-if="props.object.content.length > 0">: </t>
|
||||
<t t-if="props.object.contentType == 'getter'">
|
||||
<span class="getter-content object-content" t-att-class="objectLineClass" t-on-click.stop="() => this.store.loadGetterContent(this.props.object)">
|
||||
<t t-esc="props.object.content"/>
|
||||
@@ -20,17 +20,25 @@
|
||||
</t>
|
||||
<t t-else="">
|
||||
<span class="object-content" t-att-class="objectLineClass" t-on-dblclick.stop="setupEditMode">
|
||||
<t t-if="state.editMode">
|
||||
<t t-if="state.editMode">
|
||||
<input t-attf-id="objectEditionInput/{{pathAsString}}" t-ref="input" type="text" placeholder="" t-att-value="props.object.content" t-on-keydown.stop="editObject"/>
|
||||
</t>
|
||||
<t t-else="">
|
||||
<t t-esc="props.object.content"/>
|
||||
</t>
|
||||
</span>
|
||||
</span>
|
||||
</t>
|
||||
<span t-if="keyChanges" class="key-changes ms-1 badge p-1" title="Key additions/deletions are observed">+/-</span>
|
||||
</div>
|
||||
</div>
|
||||
<div t-if="store.contextMenu.activeMenu === contextMenuId" class="custom-menu" t-ref="contextmenu">
|
||||
<ul class="my-1">
|
||||
<li t-on-click="() => this.store.logObjectInConsole(this.props.object.path)" class="custom-menu-item py-1 px-4 text-nowrap">Store as global variable</li>
|
||||
<t t-if='props.object.contentType == "function"'>
|
||||
<li t-on-click="() => this.store.inspectFunctionSource(this.props.object.path)" class="custom-menu-item py-1 px-4 text-nowrap">Inspect function source code</li>
|
||||
</t>
|
||||
</ul>
|
||||
</div>
|
||||
<t t-if="props.object.toggled" t-key="contextMenuId">
|
||||
<t t-foreach="props.object.children" t-as="child" t-key="child_index">
|
||||
<ObjectTreeElement object="child" class="this.classFor(child)"/>
|
||||
|
||||
@@ -16,7 +16,10 @@ export class TreeElement extends Component {
|
||||
searched: false,
|
||||
});
|
||||
this.store = useStore();
|
||||
this.contextMenu = useRef("contextmenu");
|
||||
this.element = useRef("element");
|
||||
this.contextMenuId = this.store.contextMenu.id++;
|
||||
this.contextMenuEvent;
|
||||
this.stringifiedPath = JSON.stringify(this.props.component.path);
|
||||
// Scroll to the selected element when it changes
|
||||
onMounted(() => {
|
||||
@@ -35,6 +38,15 @@ export class TreeElement extends Component {
|
||||
},
|
||||
() => [this.props.component.selected]
|
||||
);
|
||||
// Open the context menu when the ids match
|
||||
useEffect(
|
||||
(menuId) => {
|
||||
if (menuId === this.contextMenuId) {
|
||||
this.store.contextMenu.open(this.contextMenuEvent, this.contextMenu.el);
|
||||
}
|
||||
},
|
||||
() => [this.store.contextMenu.activeMenu]
|
||||
);
|
||||
// Effect to apply a short highlight effect to the component when it is rendered
|
||||
useEffect(
|
||||
() => {
|
||||
@@ -74,86 +86,9 @@ export class TreeElement extends Component {
|
||||
return minimizeKey(this.props.component.key);
|
||||
}
|
||||
|
||||
get contextMenuItems() {
|
||||
return [
|
||||
{
|
||||
title: "Expand children",
|
||||
show: true,
|
||||
action: () => this.store.toggleComponentAndChildren(this.props.component, true),
|
||||
},
|
||||
{
|
||||
title: "Fold all children",
|
||||
show: true,
|
||||
action: () => this.store.toggleComponentAndChildren(this.props.component, false),
|
||||
},
|
||||
{
|
||||
title: "Fold direct children",
|
||||
show: true,
|
||||
action: () => this.store.foldDirectChildren(this.props.component),
|
||||
},
|
||||
{
|
||||
title: "Inspect source code",
|
||||
show: true,
|
||||
action: () => this.store.inspectComponent("source", this.props.component.path),
|
||||
},
|
||||
{
|
||||
title: "Store as global variable",
|
||||
show: this.props.component.path.length !== 1,
|
||||
action: () =>
|
||||
this.store.logObjectInConsole([
|
||||
...this.props.component.path,
|
||||
{ type: "item", value: "component" },
|
||||
]),
|
||||
},
|
||||
{
|
||||
title: "Inspect in Elements tab",
|
||||
show: this.props.component.path.length !== 1,
|
||||
action: () => this.store.inspectComponent("DOM", this.props.component.path),
|
||||
},
|
||||
{
|
||||
title: "Force rerender",
|
||||
show: this.props.component.path.length !== 1,
|
||||
action: () => this.store.refreshComponent(this.props.component.path),
|
||||
},
|
||||
{
|
||||
title: "Store observed states as global variable",
|
||||
show: this.props.component.path.length !== 1,
|
||||
action: () =>
|
||||
this.store.logObjectInConsole([
|
||||
...this.props.component.path,
|
||||
{ type: "item", value: "subscriptions" },
|
||||
]),
|
||||
},
|
||||
{
|
||||
title: "Inspect compiled template",
|
||||
show: this.props.component.path.length !== 1,
|
||||
action: () => this.store.inspectComponent("compiled template", this.props.component.path),
|
||||
},
|
||||
{
|
||||
title: "Log raw template",
|
||||
show: this.props.component.path.length !== 1,
|
||||
action: () => this.store.inspectComponent("raw template", this.props.component.path),
|
||||
},
|
||||
{
|
||||
title: "Store as global variable",
|
||||
show: this.props.component.path.length === 1,
|
||||
action: () => this.store.logObjectInConsole([...this.props.component.path]),
|
||||
},
|
||||
{
|
||||
title: "Don't fold component by default",
|
||||
show: this.store.settings.componentsToggleBlacklist.has(this.props.component.name),
|
||||
action: () => this.toggleComponentToBlacklist(),
|
||||
},
|
||||
{
|
||||
title: "Fold component by default",
|
||||
show: !this.store.settings.componentsToggleBlacklist.has(this.props.component.name),
|
||||
action: () => this.toggleComponentToBlacklist(),
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
openMenu(ev) {
|
||||
this.store.openContextMenu(ev, this.contextMenuItems);
|
||||
this.contextMenuEvent = ev;
|
||||
this.store.contextMenu.activeMenu = this.contextMenuId;
|
||||
}
|
||||
|
||||
// Expand/fold the component node
|
||||
|
||||
@@ -2,15 +2,15 @@
|
||||
<templates xml:space="preserve">
|
||||
<t t-name="devtools.TreeElement" owl="1">
|
||||
<div t-ref="element"
|
||||
t-att-class="{'component-selected': props.component.selected,'component-highlighted': props.component.highlighted}"
|
||||
class="tree-component m-0 p-0 w-100 text-nowrap user-select-none"
|
||||
t-on-contextmenu.prevent="openMenu"
|
||||
t-on-mouseover.stop="() => this.store.highlightComponent(props.component.path)"
|
||||
t-att-class="{'component-selected': props.component.selected,'component-highlighted': props.component.highlighted}"
|
||||
class="tree-component m-0 p-0 w-100 text-nowrap user-select-none"
|
||||
t-on-contextmenu.prevent="openMenu"
|
||||
t-on-mouseover.stop="() => this.store.highlightComponent(props.component.path)"
|
||||
t-on-click.stop="toggleComponent"
|
||||
>
|
||||
<div class="component-wrapper" t-attf-style="padding-left: {{componentPadding}}rem">
|
||||
<i class="fa px-1 pointer-icon caret"
|
||||
t-att-class="{'fa-caret-right': !props.component.toggled, 'fa-caret-down': props.component.toggled}"
|
||||
t-att-class="{'fa-caret-right': !props.component.toggled, 'fa-caret-down': props.component.toggled}"
|
||||
t-on-click.stop="toggleDisplay"
|
||||
t-attf-style="{{props.component.children.length > 0 ? '' : 'visibility: hidden;'}}"
|
||||
/>
|
||||
@@ -26,6 +26,29 @@
|
||||
<span t-if="props.component.depth">></span>
|
||||
<span class="version" t-else="">owl=<t t-esc="props.component.version"/></span>
|
||||
</div>
|
||||
<div t-if="store.contextMenu.activeMenu === contextMenuId" class="custom-menu" t-ref="contextmenu">
|
||||
<ul class="my-1">
|
||||
<li t-on-click.stop="() => this.store.toggleComponentAndChildren(props.component, true)" class="custom-menu-item py-1 px-4">Expand children</li>
|
||||
<li t-on-click.stop="() => this.store.toggleComponentAndChildren(props.component, false)" class="custom-menu-item py-1 px-4">Fold all children</li>
|
||||
<li t-on-click.stop="() => this.store.foldDirectChildren(props.component)" class="custom-menu-item py-1 px-4">Fold direct children</li>
|
||||
<li t-on-click.stop="() => this.store.inspectComponent('source', props.component.path)" class="custom-menu-item py-1 px-4">Inspect source code</li>
|
||||
<t t-if="props.component.path.length !== 1">
|
||||
<li t-on-click.stop="() => this.store.logObjectInConsole([...props.component.path, { type: 'item', value: 'component'}])" class="custom-menu-item py-1 px-4">Store as global variable</li>
|
||||
<li t-on-click.stop="() => this.store.inspectComponent('DOM', props.component.path)" class="custom-menu-item py-1 px-4">Inspect in Elements tab</li>
|
||||
<li t-on-click.stop="() => this.store.refreshComponent(props.component.path)" class="custom-menu-item py-1 px-4">Force rerender</li>
|
||||
<li t-on-click.stop="() => this.store.logObjectInConsole([...props.component.path, { type: 'item', value: 'subscriptions'}])" class="custom-menu-item py-1 px-4">Store observed states as global variable</li>
|
||||
<li t-on-click.stop="() => this.store.inspectComponent('compiled template', props.component.path)" class="custom-menu-item py-1 px-4">Inspect compiled template</li>
|
||||
<li t-on-click.stop="() => this.store.inspectComponent('raw template', props.component.path)" class="custom-menu-item py-1 px-4">Log raw template</li>
|
||||
</t>
|
||||
<t t-else="">
|
||||
<li t-on-click.stop="() => this.store.logObjectInConsole([...props.component.path])" class="custom-menu-item py-1 px-4">Store as global variable</li>
|
||||
</t>
|
||||
<li t-on-click.stop="() => this.toggleComponentToBlacklist()" class="custom-menu-item py-1 px-4">
|
||||
<t t-if="store.settings.componentsToggleBlacklist.has(props.component.name)">Don't fold component by default</t>
|
||||
<t t-else="">Fold component by default</t>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<t t-if="props.component.toggled">
|
||||
<t t-foreach="props.component.children" t-as="child" t-key="child.key">
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
const { Component } = owl;
|
||||
import { ContextMenu } from "../context_menu/context_menu";
|
||||
import { useStore } from "../store/store";
|
||||
import { ComponentsTab } from "./components_tab/components_tab";
|
||||
import { ProfilerTab } from "./profiler_tab/profiler_tab";
|
||||
import { Tab } from "./tab/tab";
|
||||
import { ProfilerTab } from "./profiler_tab/profiler_tab";
|
||||
import { useStore } from "../store/store";
|
||||
|
||||
export class DevtoolsWindow extends Component {
|
||||
static props = [];
|
||||
static template = "devtools.DevtoolsWindow";
|
||||
static components = { ComponentsTab, Tab, ProfilerTab, ContextMenu };
|
||||
static components = { ComponentsTab, Tab, ProfilerTab };
|
||||
setup() {
|
||||
this.store = useStore();
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
Owl is not loaded on this page.
|
||||
</div>
|
||||
</t>
|
||||
<ContextMenu t-if="store.contextMenu" items="store.contextMenu.items"/>
|
||||
</div>
|
||||
</t>
|
||||
</templates>
|
||||
|
||||
@@ -1,13 +1,24 @@
|
||||
import { minimizeKey } from "../../../../utils";
|
||||
import { useStore } from "../../../store/store";
|
||||
|
||||
const { Component } = owl;
|
||||
const { Component, useEffect, useRef } = owl;
|
||||
|
||||
export class Event extends Component {
|
||||
static template = "devtools.Event";
|
||||
|
||||
setup() {
|
||||
this.store = useStore();
|
||||
this.componentContextMenu = useRef("componentContextmenu");
|
||||
this.componentContextMenuId = this.store.contextMenu.id++;
|
||||
this.contextMenuEvent,
|
||||
useEffect(
|
||||
(menuId) => {
|
||||
if (menuId === this.componentContextMenuId) {
|
||||
this.store.contextMenu.open(this.contextMenuEvent, this.componentContextMenu.el);
|
||||
}
|
||||
},
|
||||
() => [this.store.contextMenu.activeMenu]
|
||||
);
|
||||
}
|
||||
|
||||
// Formatting for displaying the key of the component
|
||||
@@ -43,65 +54,13 @@ export class Event extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
get contextMenuItems() {
|
||||
return [
|
||||
{
|
||||
title: "Inspect source code",
|
||||
show: true,
|
||||
action: () => this.store.inspectComponent("source", this.props.event.path),
|
||||
},
|
||||
{
|
||||
title: "Store as global variable",
|
||||
show: this.props.event.path.length !== 1,
|
||||
action: () =>
|
||||
this.store.logObjectInConsole([
|
||||
...this.props.event.path,
|
||||
{ type: "item", value: "component" },
|
||||
]),
|
||||
},
|
||||
{
|
||||
title: "Inspect in Elements tab",
|
||||
show: this.props.event.path.length !== 1,
|
||||
action: () => this.store.inspectComponent("DOM", this.props.event.path),
|
||||
},
|
||||
{
|
||||
title: "Force rerender",
|
||||
show: this.props.event.path.length !== 1,
|
||||
action: () => this.store.refreshComponent(this.props.event.path),
|
||||
},
|
||||
{
|
||||
title: "Store observed states as global variable",
|
||||
show: this.props.event.path.length !== 1,
|
||||
action: () =>
|
||||
this.store.logObjectInConsole([
|
||||
...this.props.event.path,
|
||||
{ type: "item", value: "subscriptions" },
|
||||
]),
|
||||
},
|
||||
{
|
||||
title: "Inspect compiled template",
|
||||
show: this.props.event.path.length !== 1,
|
||||
action: () => this.store.inspectComponent("compiled template", this.props.event.path),
|
||||
},
|
||||
{
|
||||
title: "Log raw template",
|
||||
show: this.props.event.path.length !== 1,
|
||||
action: () => this.store.inspectComponent("raw template", this.props.event.path),
|
||||
},
|
||||
{
|
||||
title: "Store as global variable",
|
||||
show: this.props.event.path.length === 1,
|
||||
action: () => this.store.logObjectInConsole([...this.props.event.path]),
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
openMenu(ev) {
|
||||
openComponentMenu(ev) {
|
||||
if (this.props.event.type === "destroy") {
|
||||
return;
|
||||
} else {
|
||||
ev.preventDefault();
|
||||
this.store.openContextMenu(ev, this.contextMenuItems);
|
||||
this.contextMenuEvent = ev;
|
||||
this.store.contextMenu.activeMenu = this.componentContextMenuId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,11 +8,11 @@
|
||||
t-att-class="{'fa-caret-right': !props.event.toggled, 'fa-caret-down': props.event.toggled}"
|
||||
t-attf-style="visibility: {{props.event.origin ? '' : 'hidden'}};"
|
||||
/>
|
||||
<t t-esc="props.event.type"/>:
|
||||
<t t-esc="props.event.type"/>:
|
||||
<<span style="cursor:pointer; color: var(--component-color);"
|
||||
t-on-click.stop="() => this.store.selectComponent(props.event.path)"
|
||||
t-on-mouseover.stop="() => this.store.highlightComponent(props.event.path)"
|
||||
t-on-contextmenu="openMenu"
|
||||
t-on-click.stop="() => this.store.selectComponent(props.event.path)"
|
||||
t-on-mouseover.stop="() => this.store.highlightComponent(props.event.path)"
|
||||
t-on-contextmenu="openComponentMenu"
|
||||
t-esc="props.event.component"
|
||||
/>
|
||||
<t t-if="minimizedKey.length > 0">
|
||||
@@ -29,10 +29,10 @@
|
||||
<div class="my-0 pt-1 object-line">
|
||||
<i class="fa fa-caret-right mx-1 pe-2" style="visibility: hidden;"></i>
|
||||
<span>
|
||||
origin:
|
||||
<<span style="cursor:pointer; color: var(--component-color);"
|
||||
t-on-click.stop="() => this.store.selectComponent(props.event.origin.path)"
|
||||
t-on-mouseover.stop="() => this.store.highlightComponent(props.event.origin.path)"
|
||||
origin:
|
||||
<<span style="cursor:pointer; color: var(--component-color);"
|
||||
t-on-click.stop="() => this.store.selectComponent(props.event.origin.path)"
|
||||
t-on-mouseover.stop="() => this.store.highlightComponent(props.event.origin.path)"
|
||||
t-esc="props.event.origin.component"
|
||||
/>
|
||||
<t t-if="originMinimizedKey.length > 0">
|
||||
@@ -43,6 +43,22 @@
|
||||
</span>
|
||||
</div>
|
||||
</t>
|
||||
<div t-if="store.contextMenu.activeMenu === componentContextMenuId" class="custom-menu" t-ref="componentContextmenu">
|
||||
<ul class="my-1">
|
||||
<li t-on-click.stop="() => this.store.inspectComponent('source', props.event.path)" class="custom-menu-item py-1 px-4">Inspect source code</li>
|
||||
<t t-if="props.event.path.length !== 1">
|
||||
<li t-on-click.stop="() => this.store.logObjectInConsole([...props.event.path, { type: 'item', value: 'component'}])" class="custom-menu-item py-1 px-4">Store as global variable</li>
|
||||
<li t-on-click.stop="() => this.store.inspectComponent('DOM', props.event.path)" class="custom-menu-item py-1 px-4">Inspect in Elements tab</li>
|
||||
<li t-on-click.stop="() => this.store.refreshComponent(props.event.path)" class="custom-menu-item py-1 px-4">Force rerender</li>
|
||||
<li t-on-click.stop="() => this.store.logObjectInConsole([...props.event.path, { type: 'item', value: 'subscriptions'}])" class="custom-menu-item py-1 px-4">Store observed states as global variable</li>
|
||||
<li t-on-click.stop="() => this.store.inspectComponent('compiled template', props.event.path)" class="custom-menu-item py-1 px-4">Inspect compiled template</li>
|
||||
<li t-on-click.stop="() => this.store.inspectComponent('raw template', props.event.path)" class="custom-menu-item py-1 px-4">Log raw template</li>
|
||||
</t>
|
||||
<t t-else="">
|
||||
<li t-on-click.stop="() => this.store.logObjectInConsole([...props.event.path])" class="custom-menu-item py-1 px-4">Store as global variable</li>
|
||||
</t>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</t>
|
||||
</templates>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { minimizeKey } from "../../../../utils";
|
||||
import { useStore } from "../../../store/store";
|
||||
|
||||
const { Component } = owl;
|
||||
const { Component, useRef, useEffect } = owl;
|
||||
|
||||
export class EventNode extends Component {
|
||||
static template = "devtools.EventNode";
|
||||
@@ -10,89 +10,33 @@ export class EventNode extends Component {
|
||||
|
||||
setup() {
|
||||
this.store = useStore();
|
||||
this.nodeContextMenu = useRef("nodeContextMenu");
|
||||
this.nodeContextMenuId = this.store.contextMenu.id++;
|
||||
this.componentContextMenu = useRef("componentContextmenu");
|
||||
this.componentContextMenuId = this.store.contextMenu.id++;
|
||||
this.contextMenuEvent,
|
||||
useEffect(
|
||||
(menuId) => {
|
||||
if (menuId === this.nodeContextMenuId) {
|
||||
this.store.contextMenu.open(this.contextMenuEvent, this.nodeContextMenu.el);
|
||||
}
|
||||
if (menuId === this.componentContextMenuId) {
|
||||
this.store.contextMenu.open(this.contextMenuEvent, this.componentContextMenu.el);
|
||||
}
|
||||
},
|
||||
() => [this.store.contextMenu.activeMenu]
|
||||
);
|
||||
}
|
||||
|
||||
get eventPadding() {
|
||||
return this.props.event.depth * 0.8 + 0.3;
|
||||
}
|
||||
|
||||
get nodeContextMenuItems() {
|
||||
return [
|
||||
{
|
||||
title: "Expand children",
|
||||
show: true,
|
||||
action: () => this.store.toggleEventAndChildren(this.props.event, true),
|
||||
},
|
||||
{
|
||||
title: "Fold all children",
|
||||
show: true,
|
||||
action: () => this.store.toggleEventAndChildren(this.props.event, false),
|
||||
},
|
||||
{
|
||||
title: "Fold direct children",
|
||||
show: true,
|
||||
action: () => this.store.foldDirectChildren(this.props.event),
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
get componentContextMenuItems() {
|
||||
return [
|
||||
{
|
||||
title: "Inspect source code",
|
||||
show: true,
|
||||
action: () => this.store.inspectComponent("source", this.props.event.path),
|
||||
},
|
||||
{
|
||||
title: "Store as global variable",
|
||||
show: this.props.event.path.length !== 1,
|
||||
action: () =>
|
||||
this.store.logObjectInConsole([
|
||||
...this.props.event.path,
|
||||
{ type: "item", value: "component" },
|
||||
]),
|
||||
},
|
||||
{
|
||||
title: "Inspect in Elements tab",
|
||||
show: this.props.event.path.length !== 1,
|
||||
action: () => this.store.inspectComponent("DOM", this.props.event.path),
|
||||
},
|
||||
{
|
||||
title: "Force rerender",
|
||||
show: this.props.event.path.length !== 1,
|
||||
action: () => this.store.refreshComponent(this.props.event.path),
|
||||
},
|
||||
{
|
||||
title: "Store observed states as global variable",
|
||||
show: this.props.event.path.length !== 1,
|
||||
action: () =>
|
||||
this.store.logObjectInConsole([
|
||||
...this.props.event.path,
|
||||
{ type: "item", value: "subscriptions" },
|
||||
]),
|
||||
},
|
||||
{
|
||||
title: "Inspect compiled template",
|
||||
show: this.props.event.path.length !== 1,
|
||||
action: () => this.store.inspectComponent("compiled template", this.props.event.path),
|
||||
},
|
||||
{
|
||||
title: "Log raw template",
|
||||
show: this.props.event.path.length !== 1,
|
||||
action: () => this.store.inspectComponent("raw template", this.props.event.path),
|
||||
},
|
||||
{
|
||||
title: "Store as global variable",
|
||||
show: this.props.event.path.length === 1,
|
||||
action: () => this.store.logObjectInConsole([...this.props.event.path]),
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
openNodeMenu(ev) {
|
||||
if (this.props.event.children.length) {
|
||||
ev.preventDefault();
|
||||
this.store.openContextMenu(ev, this.nodeContextMenuItems);
|
||||
this.contextMenuEvent = ev;
|
||||
this.store.contextMenu.activeMenu = this.nodeContextMenuId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,7 +45,8 @@ export class EventNode extends Component {
|
||||
return;
|
||||
} else {
|
||||
ev.preventDefault();
|
||||
this.store.openContextMenu(ev, this.componentContextMenuItems);
|
||||
this.contextMenuEvent = ev;
|
||||
this.store.contextMenu.activeMenu = this.componentContextMenuId;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
<templates xml:space="preserve">
|
||||
<t t-name="devtools.EventNode" owl="1">
|
||||
<div class="my-0 p-0 object-line"
|
||||
t-on-click.stop="toggleDisplay"
|
||||
t-on-contextmenu="openNodeMenu"
|
||||
t-on-click.stop="toggleDisplay"
|
||||
t-on-contextmenu="openNodeMenu"
|
||||
>
|
||||
<div class="text-nowrap" t-attf-style="padding-left: {{eventPadding}}rem">
|
||||
<i class="fa px-1 pointer-icon caret"
|
||||
@@ -11,11 +11,11 @@
|
||||
t-attf-style="visibility: {{props.event.children.length > 0 ? '' : 'hidden'}};"
|
||||
/>
|
||||
<span>
|
||||
<t t-esc="props.event.type"/>:
|
||||
<<span style="cursor:pointer; color: var(--component-color);"
|
||||
t-on-click.stop="() => this.store.selectComponent(props.event.path)"
|
||||
t-on-mouseover.stop="() => this.store.highlightComponent(props.event.path)"
|
||||
t-on-contextmenu.stop="openComponentMenu"
|
||||
<t t-esc="props.event.type"/>:
|
||||
<<span style="cursor:pointer; color: var(--component-color);"
|
||||
t-on-click.stop="() => this.store.selectComponent(props.event.path)"
|
||||
t-on-mouseover.stop="() => this.store.highlightComponent(props.event.path)"
|
||||
t-on-contextmenu.stop="openComponentMenu"
|
||||
t-esc="props.event.component"/>
|
||||
<t t-if="minimizedKey.length > 0">
|
||||
<span t-if="minimizedKey.length > 0" style="color: var(--key-name);"> key</span>=<span style="color: var(--key-content);">
|
||||
@@ -28,6 +28,29 @@
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div t-if="store.contextMenu.activeMenu === nodeContextMenuId" class="custom-menu" t-ref="nodeContextMenu">
|
||||
<ul class="my-1">
|
||||
<li t-on-click.stop="() => this.store.toggleEventAndChildren(props.event, true)" class="custom-menu-item py-1 px-4">Expand children</li>
|
||||
<li t-on-click.stop="() => this.store.toggleEventAndChildren(props.event, false)" class="custom-menu-item py-1 px-4">Fold all children</li>
|
||||
<li t-on-click.stop="() => this.store.foldDirectChildren(props.event)" class="custom-menu-item py-1 px-4">Fold direct children</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div t-if="store.contextMenu.activeMenu === componentContextMenuId" class="custom-menu" t-ref="componentContextmenu">
|
||||
<ul class="my-1">
|
||||
<li t-on-click.stop="() => this.store.inspectComponent('source', props.event.path)" class="custom-menu-item py-1 px-4">Inspect source code</li>
|
||||
<t t-if="props.event.path.length !== 1">
|
||||
<li t-on-click.stop="() => this.store.logObjectInConsole([...props.event.path, { type: 'item', value: 'component'}])" class="custom-menu-item py-1 px-4">Store as global variable</li>
|
||||
<li t-on-click.stop="() => this.store.inspectComponent('DOM', props.event.path)" class="custom-menu-item py-1 px-4">Inspect in Elements tab</li>
|
||||
<li t-on-click.stop="() => this.store.refreshComponent(props.event.path)" class="custom-menu-item py-1 px-4">Force rerender</li>
|
||||
<li t-on-click.stop="() => this.store.logObjectInConsole([...props.event.path, { type: 'item', value: 'subscriptions'}])" class="custom-menu-item py-1 px-4">Store observed states as global variable</li>
|
||||
<li t-on-click.stop="() => this.store.inspectComponent('compiled template', props.event.path)" class="custom-menu-item py-1 px-4">Inspect compiled template</li>
|
||||
<li t-on-click.stop="() => this.store.inspectComponent('raw template', props.event.path)" class="custom-menu-item py-1 px-4">Log raw template</li>
|
||||
</t>
|
||||
<t t-else="">
|
||||
<li t-on-click.stop="() => this.store.logObjectInConsole([...props.event.path])" class="custom-menu-item py-1 px-4">Store as global variable</li>
|
||||
</t>
|
||||
</ul>
|
||||
</div>
|
||||
<t t-if="props.event.toggled">
|
||||
<t t-foreach="props.event.children" t-as="child" t-key="child.id">
|
||||
<EventNode event="child"/>
|
||||
|
||||
@@ -11,7 +11,30 @@ export const store = reactive({
|
||||
darkmode: false,
|
||||
componentsToggleBlacklist: new Set(),
|
||||
},
|
||||
contextMenu: null,
|
||||
contextMenu: {
|
||||
id: 0,
|
||||
activeMenu: -1,
|
||||
// Opens the context menu corresponding with the given menu html element
|
||||
open(event, menu) {
|
||||
const menuWidth = menu.offsetWidth;
|
||||
const menuHeight = menu.offsetHeight;
|
||||
let x = event.clientX;
|
||||
let y = event.clientY;
|
||||
if (x + menuWidth > window.innerWidth) {
|
||||
x = window.innerWidth - menuWidth;
|
||||
}
|
||||
if (y + menuHeight > window.innerHeight) {
|
||||
y = window.innerHeight - menuHeight;
|
||||
}
|
||||
menu.style.left = x + "px";
|
||||
// Need 25px offset because of the main navbar from the browser devtools
|
||||
menu.style.top = y - 25 + "px";
|
||||
},
|
||||
// Close the currently displayed context menu
|
||||
close() {
|
||||
this.activeMenu = -1;
|
||||
},
|
||||
},
|
||||
isFirefox: IS_FIREFOX,
|
||||
frameUrls: ["top"],
|
||||
activeFrame: "top",
|
||||
@@ -33,11 +56,9 @@ export const store = reactive({
|
||||
props: { toggled: true, children: [] },
|
||||
env: { toggled: false, children: [] },
|
||||
instance: { toggled: true, children: [] },
|
||||
hooks: { toggled: true, children: [] },
|
||||
version: "1.0",
|
||||
},
|
||||
selectedElement: null,
|
||||
observedVariables: [],
|
||||
componentSearch: {
|
||||
search: "",
|
||||
searchResults: [],
|
||||
@@ -72,16 +93,6 @@ export const store = reactive({
|
||||
evalFunctionInWindow("disableHTMLSelector", [], this.activeFrame);
|
||||
},
|
||||
|
||||
openContextMenu(event, items) {
|
||||
this.contextMenu = {
|
||||
position: {
|
||||
x: event.clientX,
|
||||
y: event.clientY,
|
||||
},
|
||||
items,
|
||||
};
|
||||
},
|
||||
|
||||
// Load all data related to the components tree using the global hook loaded on the page
|
||||
// Use fromOld to specify if we want to keep most of the toggled/selected data of the old tree
|
||||
// when generating the new one
|
||||
@@ -566,42 +577,6 @@ export const store = reactive({
|
||||
}
|
||||
},
|
||||
|
||||
async injectBreakpoint(hook, path, instanceOnly = false, condition = "1") {
|
||||
path = [...path];
|
||||
await evalFunctionInWindow(
|
||||
"injectBreakpoint",
|
||||
[hook, path, instanceOnly, condition],
|
||||
this.activeFrame
|
||||
);
|
||||
await this.loadComponentsTree(true);
|
||||
},
|
||||
|
||||
async removeBreakpoints() {
|
||||
await evalFunctionInWindow("removeBreakpoints", [], this.activeFrame);
|
||||
await this.loadComponentsTree(true);
|
||||
},
|
||||
|
||||
async observeVariable(path) {
|
||||
this.observedVariables.push({ path: [...path], visible: false });
|
||||
this.observedVariables = await evalFunctionInWindow(
|
||||
"getObservedVariables",
|
||||
[store.observedVariables],
|
||||
store.activeFrame
|
||||
);
|
||||
await browserInstance.storage.local.set({
|
||||
observedVariables: toRaw(this.observedVariables).map((o) => o.path),
|
||||
});
|
||||
},
|
||||
|
||||
clearObservedVariable(index) {
|
||||
if (index !== undefined) {
|
||||
this.observedVariables.splice(index, 1);
|
||||
} else {
|
||||
this.observedVariables = [];
|
||||
}
|
||||
browserInstance.storage.local.set({ observedVariables: toRaw(this.observedVariables) });
|
||||
},
|
||||
|
||||
// Trigger the highlight on the component in the page
|
||||
highlightComponent(path) {
|
||||
evalFunctionInWindow("highlightComponent", [path], this.activeFrame);
|
||||
@@ -671,9 +646,8 @@ async function init() {
|
||||
store.updateIFrameList();
|
||||
|
||||
// Global listeners to close the currently shown context menu when the user clicks or opens another
|
||||
document.addEventListener("click", () => (store.contextMenu = null), { capture: true });
|
||||
document.addEventListener("contextmenu", () => (store.contextMenu = null), { capture: true });
|
||||
window.addEventListener("blur", () => (store.contextMenu = null), { capture: true });
|
||||
document.addEventListener("click", () => store.contextMenu.close(), { capture: true });
|
||||
document.addEventListener("contextmenu", () => store.contextMenu.close(), { capture: true });
|
||||
|
||||
// Make sure the events recorder is at its initial state in every frame
|
||||
for (const frame of store.frameUrls) {
|
||||
@@ -692,16 +666,6 @@ async function init() {
|
||||
}
|
||||
}
|
||||
}, 500);
|
||||
// Refresh observed variables values every 200 ms
|
||||
setInterval(async () => {
|
||||
if (store.owlStatus) {
|
||||
store.observedVariables = await evalFunctionInWindow(
|
||||
"getObservedVariables",
|
||||
[[...store.observedVariables]],
|
||||
store.activeFrame
|
||||
);
|
||||
}
|
||||
}, 200);
|
||||
}
|
||||
|
||||
let rootRendersTimeout = false;
|
||||
@@ -796,16 +760,6 @@ async function loadSettings() {
|
||||
storage.owlDevtoolsComponentsToggleBlacklist
|
||||
);
|
||||
}
|
||||
// Observed variables
|
||||
if (storage.observedVariables) {
|
||||
store.observedVariables = [];
|
||||
for (const path of storage.observedVariables) {
|
||||
store.observedVariables.push({
|
||||
path: [...path],
|
||||
visible: false,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Function to handle and store a batch of events coming from the page
|
||||
|
||||
@@ -51,8 +51,6 @@
|
||||
this.requestedFrame = false;
|
||||
this.enabledSelector = false;
|
||||
this.eventsBatch = [];
|
||||
this.breakpointsClassMap = new Map();
|
||||
this.breakpointsHookMap = new Map();
|
||||
// Object which defines how different types of data should be displayed when passed to the devtools
|
||||
this.serializer = {
|
||||
// Defines how leaf object nodes should be displayed in the extension when inside a bigger structure
|
||||
@@ -60,16 +58,15 @@
|
||||
// The asConstructorName parameter can be passed to change the display of objects and functions to
|
||||
// be their constructor name (useful for prototype, map and set display)
|
||||
serializeItem(value, asConstructorName = false) {
|
||||
if (typeof value === "object") {
|
||||
if (typeof value === "array") {
|
||||
return "Array(" + value.length + ")";
|
||||
} else if (typeof value === "object") {
|
||||
if (value == null) {
|
||||
return "null";
|
||||
}
|
||||
if (asConstructorName) {
|
||||
return value.constructor.name;
|
||||
}
|
||||
if (value instanceof Array) {
|
||||
return "Array(" + value.length + ")";
|
||||
}
|
||||
return "{...}";
|
||||
} else if (typeof value === "undefined") {
|
||||
return "undefined";
|
||||
@@ -119,17 +116,12 @@
|
||||
} else if (obj instanceof Number) {
|
||||
result[0] = obj.toString();
|
||||
} else {
|
||||
for (const key of Reflect.ownKeys(obj)) {
|
||||
for (const [key, value] of Object.entries(obj)) {
|
||||
if (length > 25) {
|
||||
result.push("...");
|
||||
break;
|
||||
}
|
||||
let element;
|
||||
if (Object.getOwnPropertyDescriptor(obj, key).hasOwnProperty("get")) {
|
||||
element = key.toString() + ": (...)";
|
||||
} else {
|
||||
element = key.toString() + ": " + this.serializeItem(obj[key]);
|
||||
}
|
||||
const element = key + ": " + this.serializeItem(value);
|
||||
length += element.length;
|
||||
result.push(element);
|
||||
}
|
||||
@@ -143,7 +135,7 @@
|
||||
result.push(element);
|
||||
}
|
||||
}
|
||||
if (obj.constructor && obj.constructor.name !== "Object") {
|
||||
if (obj.constructor.name !== "Object") {
|
||||
return obj.constructor.name + " {" + result.join(", ") + "}";
|
||||
}
|
||||
return "{" + result.join(", ") + "}";
|
||||
@@ -703,7 +695,7 @@
|
||||
try {
|
||||
obj = Object.getOwnPropertyDescriptor(obj, key.value).get.call(obj);
|
||||
} catch (e) {
|
||||
obj = "Exception: " + e.toString();
|
||||
obj = e.toString();
|
||||
}
|
||||
break;
|
||||
case "prototype getter":
|
||||
@@ -721,13 +713,13 @@
|
||||
try {
|
||||
obj = Object.getOwnPropertyDescriptor(obj, key.value).get;
|
||||
} catch (e) {
|
||||
obj = "Exception: " + e.toString();
|
||||
obj = e.toString();
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
obj = obj[key.value];
|
||||
} catch (e) {
|
||||
obj = "Exception: " + e.toString();
|
||||
obj = e.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -740,20 +732,15 @@
|
||||
|
||||
// Returns the asked property given its global path
|
||||
getObjectProperty(path) {
|
||||
// Just return the corresponding app if path is of length 1 and not simplified
|
||||
if (path.length === 1 && !isNaN(path[0])) {
|
||||
// Just return the corresponding app if path is of length 1
|
||||
if (path.length === 1) {
|
||||
return [...this.apps][path[0]];
|
||||
}
|
||||
// Path to the component node is only strings, becomes objects for properties
|
||||
const index = path.findIndex((key) => typeof key !== "string");
|
||||
if (index === -1) {
|
||||
return this.getComponentNode(path);
|
||||
}
|
||||
const componentNode = this.getComponentNode(index === 1 ? [path[0]] : path.slice(0, index));
|
||||
if (componentNode) {
|
||||
return this.getObject(componentNode, path.slice(index));
|
||||
}
|
||||
return "Exception: component not found";
|
||||
const componentNode = this.getComponentNode(path.slice(0, index));
|
||||
const obj = this.getObject(componentNode, path.slice(index));
|
||||
return obj;
|
||||
}
|
||||
|
||||
// Returns a modified version of an object node that has compatible format with the devtools ObjectTreeElement component
|
||||
@@ -801,11 +788,6 @@
|
||||
child.name = "value";
|
||||
obj = parentObj[1];
|
||||
break;
|
||||
case "getter":
|
||||
child.name = key.value;
|
||||
obj = parentObj[key.value];
|
||||
break;
|
||||
case "prototype getter":
|
||||
case "set entry":
|
||||
case "map entry":
|
||||
case "item":
|
||||
@@ -821,8 +803,6 @@
|
||||
parentObj
|
||||
).findIndex((sym) => sym === key.value);
|
||||
child.path[child.path.length - 1].value = key.value.toString();
|
||||
} else if (key.hasOwnProperty("symbolIndex")) {
|
||||
obj = parentObj[Object.getOwnPropertySymbols(parentObj)[key.symbolIndex]];
|
||||
} else {
|
||||
obj = parentObj[key.value];
|
||||
}
|
||||
@@ -854,7 +834,7 @@
|
||||
child.contentType = "set";
|
||||
child.hasChildren = true;
|
||||
break;
|
||||
case obj.constructor?.name === "Array":
|
||||
case obj.constructor.name === "Array":
|
||||
child.contentType = "array";
|
||||
child.hasChildren = obj.length > 0;
|
||||
break;
|
||||
@@ -862,11 +842,11 @@
|
||||
child.contentType = "function";
|
||||
child.hasChildren = true;
|
||||
break;
|
||||
case typeof obj === "object":
|
||||
case obj instanceof Object:
|
||||
child.contentType = "object";
|
||||
child.hasChildren =
|
||||
Object.keys(obj).length > 0 ||
|
||||
Object.getOwnPropertySymbols(obj).length > 0 ||
|
||||
Object.keys(obj).length ||
|
||||
Object.getOwnPropertySymbols(obj).length ||
|
||||
obj.constructor.name !== "Object";
|
||||
break;
|
||||
default:
|
||||
@@ -910,15 +890,12 @@
|
||||
path.shift();
|
||||
}
|
||||
// the value is either "props" or "env" here
|
||||
if (objType !== "instance" && objType !== "hook") {
|
||||
if (objType !== "instance") {
|
||||
obj = oldTree[path[0].value].children;
|
||||
path.shift();
|
||||
// there is nothing otherwise but extension side it is in instance
|
||||
} else if (objType === "instance") {
|
||||
obj = oldTree.instance.children;
|
||||
} else {
|
||||
obj = oldTree.hooks.children;
|
||||
path.shift();
|
||||
obj = oldTree.instance.children;
|
||||
}
|
||||
// the first element here is directly in an array instead of a children array
|
||||
obj = obj[path[0].childIndex];
|
||||
@@ -1049,40 +1026,36 @@
|
||||
break;
|
||||
case "object":
|
||||
case "function":
|
||||
Reflect.ownKeys(obj)
|
||||
.sort(compareKeys)
|
||||
.forEach((key) => {
|
||||
if (
|
||||
key !== "__proto__" &&
|
||||
Object.getOwnPropertyDescriptor(obj, key).hasOwnProperty("get")
|
||||
) {
|
||||
let child = {
|
||||
name: key,
|
||||
depth: depth,
|
||||
toggled: false,
|
||||
objectType: objType,
|
||||
path: [...path, { type: "getter", value: key, childIndex: children.length }],
|
||||
contentType: "getter",
|
||||
content: "(...)",
|
||||
hasChildren: false,
|
||||
children: [],
|
||||
};
|
||||
children.push(child);
|
||||
}
|
||||
const child = this.serializeObjectChild(
|
||||
obj,
|
||||
{ type: "item", value: key, childIndex: children.length },
|
||||
depth,
|
||||
objType,
|
||||
path,
|
||||
oldBranch?.children[index],
|
||||
oldTree
|
||||
);
|
||||
if (child) {
|
||||
children.push(child);
|
||||
}
|
||||
index++;
|
||||
});
|
||||
Reflect.ownKeys(obj).forEach((key) => {
|
||||
if (
|
||||
key !== "__proto__" &&
|
||||
Object.getOwnPropertyDescriptor(obj, key).hasOwnProperty("get")
|
||||
) {
|
||||
let child = {
|
||||
name: key,
|
||||
depth: depth,
|
||||
toggled: false,
|
||||
objectType: objType,
|
||||
path: [...path, { type: "getter", value: key, childIndex: children.length }],
|
||||
contentType: "getter",
|
||||
content: "(...)",
|
||||
hasChildren: false,
|
||||
children: [],
|
||||
};
|
||||
children.push(child);
|
||||
}
|
||||
const child = this.serializeObjectChild(
|
||||
obj,
|
||||
{ type: "item", value: key, childIndex: children.length },
|
||||
depth,
|
||||
objType,
|
||||
path,
|
||||
oldBranch?.children[index],
|
||||
oldTree
|
||||
);
|
||||
if (child) children.push(child);
|
||||
index++;
|
||||
});
|
||||
}
|
||||
let proto = Object.getPrototypeOf(obj);
|
||||
while (proto) {
|
||||
@@ -1126,44 +1099,25 @@
|
||||
}
|
||||
// Returns the Component node given its path and the root component node
|
||||
getComponentNode(path) {
|
||||
// All paths that consists in an array containing a single stringified number lead to an app
|
||||
if (path.length === 1 && !isNaN(path[0])) {
|
||||
// The node is an app and not a component
|
||||
if (path.length === 1) {
|
||||
return [...this.apps][path[0]];
|
||||
}
|
||||
let node;
|
||||
// If the path is longer and its first item is indeed an app number, it is a regular path
|
||||
if (!isNaN(path[0])) {
|
||||
// The second element in the path will always be the root of the app
|
||||
node = [...this.apps][path[0]]?.root;
|
||||
if (!node) {
|
||||
// The second element in the path will always be the root of the app
|
||||
let node = [...this.apps][path[0]]?.root;
|
||||
if (!node) {
|
||||
return null;
|
||||
}
|
||||
for (let i = 2; i < path.length; i++) {
|
||||
// From this point onwards, it is an object path inside the component node
|
||||
if (typeof path[i] !== "string") {
|
||||
break;
|
||||
}
|
||||
if (node.children.hasOwnProperty(path[i])) {
|
||||
node = node.children[path[i]];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
for (let i = 2; i < path.length; i++) {
|
||||
// From this point onwards, it is an object path inside the component node
|
||||
if (typeof path[i] !== "string") {
|
||||
break;
|
||||
}
|
||||
if (node.children.hasOwnProperty(path[i])) {
|
||||
node = node.children[path[i]];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
// If the first path item is a more complex string, it is a simplified path where elements
|
||||
// are a series of component names and indexes separated by slashes
|
||||
} else {
|
||||
const simplifiedPathArray = path[0].split("/");
|
||||
node = [...this.apps][simplifiedPathArray[0]]?.root;
|
||||
if (node.name !== simplifiedPathArray[1]) {
|
||||
return null;
|
||||
}
|
||||
for (let i = 2; i < simplifiedPathArray.length; i += 2) {
|
||||
const key = Reflect.ownKeys(node.children)[simplifiedPathArray[i]];
|
||||
node = node.children[key];
|
||||
if (node.name !== simplifiedPathArray[i + 1]) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
return node;
|
||||
}
|
||||
@@ -1201,46 +1155,42 @@
|
||||
const propsPath = isApp
|
||||
? [...path, { type: "item", value: "props" }]
|
||||
: [...path, { type: "item", value: "component" }, { type: "item", value: "props" }];
|
||||
Reflect.ownKeys(props)
|
||||
.sort(compareKeys)
|
||||
.forEach((key) => {
|
||||
let oldBranch = oldTree?.props.children[component.props.children.length];
|
||||
const property = this.serializeObjectChild(
|
||||
props,
|
||||
{ type: "item", value: key, childIndex: component.props.children.length },
|
||||
0,
|
||||
"props",
|
||||
propsPath,
|
||||
oldBranch,
|
||||
oldTree
|
||||
);
|
||||
if (property) {
|
||||
component.props.children.push(property);
|
||||
}
|
||||
});
|
||||
Reflect.ownKeys(props).forEach((key) => {
|
||||
let oldBranch = oldTree?.props.children[component.props.children.length];
|
||||
const property = this.serializeObjectChild(
|
||||
props,
|
||||
{ type: "item", value: key, childIndex: component.props.children.length },
|
||||
0,
|
||||
"props",
|
||||
propsPath,
|
||||
oldBranch,
|
||||
oldTree
|
||||
);
|
||||
if (property) {
|
||||
component.props.children.push(property);
|
||||
}
|
||||
});
|
||||
// Load env of the component
|
||||
const env = isApp ? node.env : node.component.env;
|
||||
component.env = { toggled: oldTree ? oldTree.env.toggled : false, children: [] };
|
||||
const envPath = isApp
|
||||
? [...path, { type: "item", value: "env" }]
|
||||
: [...path, { type: "item", value: "component" }, { type: "item", value: "env" }];
|
||||
Reflect.ownKeys(env)
|
||||
.sort(compareKeys)
|
||||
.forEach((key) => {
|
||||
let oldBranch = oldTree?.env.children[component.env.children.length];
|
||||
const envElement = this.serializeObjectChild(
|
||||
env,
|
||||
{ type: "item", value: key, childIndex: component.env.children.length },
|
||||
0,
|
||||
"env",
|
||||
envPath,
|
||||
oldBranch,
|
||||
oldTree
|
||||
);
|
||||
if (envElement) {
|
||||
component.env.children.push(envElement);
|
||||
}
|
||||
});
|
||||
Reflect.ownKeys(env).forEach((key) => {
|
||||
let oldBranch = oldTree?.env.children[component.env.children.length];
|
||||
const envElement = this.serializeObjectChild(
|
||||
env,
|
||||
{ type: "item", value: key, childIndex: component.env.children.length },
|
||||
0,
|
||||
"env",
|
||||
envPath,
|
||||
oldBranch,
|
||||
oldTree
|
||||
);
|
||||
if (envElement) {
|
||||
component.env.children.push(envElement);
|
||||
}
|
||||
});
|
||||
// Load env getters
|
||||
let obj = Object.getPrototypeOf(env);
|
||||
Reflect.ownKeys(obj).forEach((key) => {
|
||||
@@ -1279,25 +1229,23 @@
|
||||
const instance = isApp ? node : node.component;
|
||||
component.instance = { toggled: oldTree ? oldTree.instance.toggled : true, children: [] };
|
||||
const instancePath = isApp ? path : [...path, { type: "item", value: "component" }];
|
||||
Reflect.ownKeys(instance)
|
||||
.sort(compareKeys)
|
||||
.forEach((key) => {
|
||||
if (!["env", "props"].includes(key)) {
|
||||
let oldBranch = oldTree?.instance.children[component.instance.children.length];
|
||||
const instanceElement = this.serializeObjectChild(
|
||||
instance,
|
||||
{ type: "item", value: key, childIndex: component.instance.children.length },
|
||||
0,
|
||||
"instance",
|
||||
instancePath,
|
||||
oldBranch,
|
||||
oldTree
|
||||
);
|
||||
if (instanceElement) {
|
||||
component.instance.children.push(instanceElement);
|
||||
}
|
||||
Reflect.ownKeys(instance).forEach((key) => {
|
||||
if (!["env", "props"].includes(key)) {
|
||||
let oldBranch = oldTree?.instance.children[component.instance.children.length];
|
||||
const instanceElement = this.serializeObjectChild(
|
||||
instance,
|
||||
{ type: "item", value: key, childIndex: component.instance.children.length },
|
||||
0,
|
||||
"instance",
|
||||
instancePath,
|
||||
oldBranch,
|
||||
oldTree
|
||||
);
|
||||
if (instanceElement) {
|
||||
component.instance.children.push(instanceElement);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
// Load instance getters
|
||||
obj = Object.getPrototypeOf(instance);
|
||||
while (obj) {
|
||||
@@ -1413,39 +1361,6 @@
|
||||
component.subscriptions.children.push(subscription);
|
||||
});
|
||||
}
|
||||
// Load hooks of the component
|
||||
if (!isApp) {
|
||||
component.hooks = { toggled: oldTree ? oldTree.hooks.toggled : true, children: [] };
|
||||
const hooksList = [
|
||||
"mounted",
|
||||
"patched",
|
||||
"willDestroy",
|
||||
"willPatch",
|
||||
"willStart",
|
||||
"willUnmount",
|
||||
"willUpdateProps",
|
||||
];
|
||||
const hooksPath = [...instancePath, { type: "item", value: "__owl__" }];
|
||||
Reflect.ownKeys(instance.__owl__)
|
||||
.sort(compareKeys)
|
||||
.forEach((key) => {
|
||||
if (hooksList.includes(key)) {
|
||||
let oldBranch = oldTree?.hooks.children[component.hooks.children.length];
|
||||
const property = this.serializeObjectChild(
|
||||
instance.__owl__,
|
||||
{ type: "item", value: key, childIndex: component.hooks.children.length },
|
||||
0,
|
||||
"hook",
|
||||
hooksPath,
|
||||
oldBranch,
|
||||
oldTree
|
||||
);
|
||||
if (property) {
|
||||
component.hooks.children.push(property);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return component;
|
||||
}
|
||||
// Replace the content of a parsed getter object with the result of the corresponding get method
|
||||
@@ -1720,37 +1635,6 @@
|
||||
}
|
||||
return children;
|
||||
}
|
||||
getObservedVariables(current) {
|
||||
const res = [...current];
|
||||
for (let i = 0; i < current.length; i++) {
|
||||
const path = current[i].path;
|
||||
const parent = this.getObjectProperty(path.slice(0, path.length - 1));
|
||||
if (parent && !(typeof parent === "string" && parent.startsWith("Exception: "))) {
|
||||
const result = this.serializeObjectChild(
|
||||
parent,
|
||||
path.at(-1),
|
||||
0,
|
||||
"observed",
|
||||
path.slice(0, path.length - 1),
|
||||
{},
|
||||
{}
|
||||
);
|
||||
result.hasChildren = false;
|
||||
result.visible = true;
|
||||
const index = path.findIndex((key) => typeof key !== "string");
|
||||
if (index > 1) {
|
||||
const componentNode = this.getComponentNode(path.slice(0, index));
|
||||
result.path = [this.getComponentSimplifiedPath(componentNode)].concat(
|
||||
path.slice(index)
|
||||
);
|
||||
}
|
||||
res[i] = result;
|
||||
} else {
|
||||
res[i].visible = false;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
// Returns the path of the given component node
|
||||
getComponentPath(componentNode) {
|
||||
let path = [];
|
||||
@@ -1767,23 +1651,6 @@
|
||||
path.unshift(index.toString());
|
||||
return path;
|
||||
}
|
||||
// Returns the simplified path of the given component node (using component names and indexes)
|
||||
getComponentSimplifiedPath(componentNode) {
|
||||
let path = componentNode.name;
|
||||
if (componentNode.parentKey) {
|
||||
while (componentNode.parent) {
|
||||
const previousKey = componentNode.parentKey;
|
||||
componentNode = componentNode.parent;
|
||||
path = `${componentNode.name}/${Reflect.ownKeys(componentNode.children).indexOf(
|
||||
previousKey
|
||||
)}/${path}`;
|
||||
}
|
||||
}
|
||||
const appsArray = [...this.apps];
|
||||
let index = appsArray.findIndex((app) => app === componentNode.app);
|
||||
path = index.toString() + (path.length ? `/${path}` : "");
|
||||
return path;
|
||||
}
|
||||
// Store the object into a temp window variable and log it to the console
|
||||
sendObjectToConsole(path) {
|
||||
const obj = this.getObjectProperty(path);
|
||||
@@ -1831,48 +1698,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
injectBreakpoint(hook, path, instanceOnly, condition) {
|
||||
const componentNode = this.getObjectProperty(path);
|
||||
const injectFunctionInHook = (comp, hook, fn) => {
|
||||
comp[hook].push(fn);
|
||||
};
|
||||
const originalHook = [...componentNode.component.__owl__[hook]];
|
||||
injectFunctionInHook(componentNode.component.__owl__, hook, () => {
|
||||
debugger;
|
||||
});
|
||||
if (!this.breakpointsHookMap.get([componentNode.component.__owl__, hook])) {
|
||||
this.breakpointsHookMap.set([componentNode.component.__owl__, hook], originalHook);
|
||||
}
|
||||
if (!instanceOnly) {
|
||||
const componentClass = componentNode.component.constructor;
|
||||
const originalSetup = componentClass.prototype.setup;
|
||||
if (!this.breakpointsClassMap.get(componentClass)) {
|
||||
this.breakpointsClassMap.set(componentClass, originalSetup);
|
||||
}
|
||||
componentClass.prototype.setup = function () {
|
||||
const debuggerFunc = () => {
|
||||
if (eval(condition)) {
|
||||
this;
|
||||
debugger;
|
||||
}
|
||||
};
|
||||
injectFunctionInHook(this.__owl__, hook, debuggerFunc);
|
||||
originalSetup.call(this, ...arguments);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
removeBreakpoints() {
|
||||
for (const [component, setup] of this.breakpointsClassMap) {
|
||||
component.prototype.setup = setup;
|
||||
}
|
||||
this.breakpointsClassMap.clear();
|
||||
for (const [ref, originalHook] of this.breakpointsHookMap) {
|
||||
ref[0][ref[1]] = originalHook;
|
||||
}
|
||||
this.breakpointsHookMap.clear();
|
||||
}
|
||||
|
||||
targetName(target, node) {
|
||||
// check on component
|
||||
const { component } = node;
|
||||
@@ -1922,19 +1747,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
function compareKeys(a, b) {
|
||||
const isSymbolA = typeof a === "symbol";
|
||||
const isSymbolB = typeof b === "symbol";
|
||||
|
||||
if (isSymbolA && !isSymbolB) {
|
||||
return 1; // Place Symbols at the end
|
||||
} else if (!isSymbolA && isSymbolB) {
|
||||
return -1; // Place non-Symbols at the beginning
|
||||
} else {
|
||||
return String(a).localeCompare(String(b), undefined, { numeric: true }); // Sort other keys alphabetically
|
||||
}
|
||||
}
|
||||
|
||||
function checkOwlStatus() {
|
||||
let owlStatus = 2;
|
||||
if (!window.__OWL__DEVTOOLS_GLOBAL_HOOK__) {
|
||||
|
||||
@@ -140,6 +140,7 @@ async function startRelease() {
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
log(`Step ${step++}/${STEPS}: Creating the release...`);
|
||||
const relaseResult = await execCommand(`gh release create v${next} dist/*.js dist/*.zip ${draft} -F ${file}`);
|
||||
if (relaseResult !== 0) {
|
||||
|
||||