summaryrefslogtreecommitdiff
path: root/preact/devtools
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2021-08-23 16:46:06 -0300
committerSebastian <sebasjm@gmail.com>2021-08-23 16:48:30 -0300
commit38acabfa6089ab8ac469c12b5f55022fb96935e5 (patch)
tree453dbf70000cc5e338b06201af1eaca8343f8f73 /preact/devtools
parentf26125e039143b92dc0d84e7775f508ab0cdcaa8 (diff)
downloadnode-vendor-master.tar.gz
node-vendor-master.tar.bz2
node-vendor-master.zip
added web vendorsHEADmaster
Diffstat (limited to 'preact/devtools')
-rw-r--r--preact/devtools/LICENSE21
-rw-r--r--preact/devtools/mangle.json21
-rw-r--r--preact/devtools/package.json16
-rw-r--r--preact/devtools/src/devtools.js10
-rw-r--r--preact/devtools/src/index.d.ts8
-rw-r--r--preact/devtools/src/index.js15
-rw-r--r--preact/devtools/test/browser/addHookName.test.js51
7 files changed, 142 insertions, 0 deletions
diff --git a/preact/devtools/LICENSE b/preact/devtools/LICENSE
new file mode 100644
index 0000000..da5389a
--- /dev/null
+++ b/preact/devtools/LICENSE
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) 2015-present Jason Miller
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/preact/devtools/mangle.json b/preact/devtools/mangle.json
new file mode 100644
index 0000000..506a6a4
--- /dev/null
+++ b/preact/devtools/mangle.json
@@ -0,0 +1,21 @@
+{
+ "help": {
+ "what is this file?": "It controls protected/private property mangling so that minified builds have consistent property names.",
+ "why are there duplicate minified properties?": "Most properties are only used on one type of objects, so they can have the same name since they will never collide. Doing this reduces size."
+ },
+ "minify": {
+ "mangle": {
+ "properties": {
+ "regex": "^_[^_]",
+ "reserved": [
+ "__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED",
+ "__REACT_DEVTOOLS_GLOBAL_HOOK__",
+ "__PREACT_DEVTOOLS__",
+ "_renderers",
+ "__source",
+ "__self"
+ ]
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/preact/devtools/package.json b/preact/devtools/package.json
new file mode 100644
index 0000000..92beb75
--- /dev/null
+++ b/preact/devtools/package.json
@@ -0,0 +1,16 @@
+{
+ "name": "preact-devtools",
+ "amdName": "preactDevtools",
+ "version": "1.0.0",
+ "private": true,
+ "description": "Preact bridge for Preact devtools",
+ "main": "dist/devtools.js",
+ "module": "dist/devtools.module.js",
+ "umd:main": "dist/devtools.umd.js",
+ "source": "src/index.js",
+ "license": "MIT",
+ "types": "src/index.d.ts",
+ "peerDependencies": {
+ "preact": "^10.0.0"
+ }
+}
diff --git a/preact/devtools/src/devtools.js b/preact/devtools/src/devtools.js
new file mode 100644
index 0000000..2bd462d
--- /dev/null
+++ b/preact/devtools/src/devtools.js
@@ -0,0 +1,10 @@
+import { options, Fragment, Component } from 'preact';
+
+export function initDevTools() {
+ if (typeof window != 'undefined' && window.__PREACT_DEVTOOLS__) {
+ window.__PREACT_DEVTOOLS__.attachPreact('10.5.14', options, {
+ Fragment,
+ Component
+ });
+ }
+}
diff --git a/preact/devtools/src/index.d.ts b/preact/devtools/src/index.d.ts
new file mode 100644
index 0000000..230e5ab
--- /dev/null
+++ b/preact/devtools/src/index.d.ts
@@ -0,0 +1,8 @@
+/**
+ * Customize the displayed name of a useState, useReducer or useRef hook
+ * in the devtools panel.
+ *
+ * @param value Wrapped native hook.
+ * @param name Custom name
+ */
+export function addHookName<T>(value: T, name: string): T;
diff --git a/preact/devtools/src/index.js b/preact/devtools/src/index.js
new file mode 100644
index 0000000..693429f
--- /dev/null
+++ b/preact/devtools/src/index.js
@@ -0,0 +1,15 @@
+import { options } from 'preact';
+import { initDevTools } from './devtools';
+
+initDevTools();
+
+/**
+ * Display a custom label for a custom hook for the devtools panel
+ * @type {<T>(value: T, name: string) => T}
+ */
+export function addHookName(value, name) {
+ if (options._addHookName) {
+ options._addHookName(name);
+ }
+ return value;
+}
diff --git a/preact/devtools/test/browser/addHookName.test.js b/preact/devtools/test/browser/addHookName.test.js
new file mode 100644
index 0000000..28b06b0
--- /dev/null
+++ b/preact/devtools/test/browser/addHookName.test.js
@@ -0,0 +1,51 @@
+import { createElement, render, options } from 'preact';
+import { setupScratch, teardown } from '../../../test/_util/helpers';
+import { useState } from 'preact/hooks';
+import { addHookName } from 'preact/devtools';
+
+/** @jsx createElement */
+
+describe('addHookName', () => {
+ /** @type {HTMLDivElement} */
+ let scratch;
+
+ beforeEach(() => {
+ scratch = setupScratch();
+ });
+
+ afterEach(() => {
+ teardown(scratch);
+ delete options._addHookName;
+ });
+
+ it('should do nothing when no options hook is present', () => {
+ function useFoo() {
+ return addHookName(useState(0), 'foo');
+ }
+
+ function App() {
+ let [v] = useFoo();
+ return <div>{v}</div>;
+ }
+
+ expect(() => render(<App />, scratch)).to.not.throw();
+ });
+
+ it('should call options hook with value', () => {
+ let spy = (options._addHookName = sinon.spy());
+
+ function useFoo() {
+ return addHookName(useState(0), 'foo');
+ }
+
+ function App() {
+ let [v] = useFoo();
+ return <div>{v}</div>;
+ }
+
+ render(<App />, scratch);
+
+ expect(spy).to.be.calledOnce;
+ expect(spy).to.be.calledWith('foo');
+ });
+});