@editframe/react 0.16.7-beta.0 → 0.17.6-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,9 @@
1
- import { EFTimeDisplay } from "@editframe/elements";
2
- import { createComponent } from "@lit/react";
3
1
  import React from "react";
2
+ import { createComponent } from "@lit/react";
3
+ import { EFTimeDisplay } from "@editframe/elements";
4
4
  const TimeDisplay = createComponent({
5
- tagName: "ef-time-display",
6
- elementClass: EFTimeDisplay,
7
- react: React
5
+ tagName: "ef-time-display",
6
+ elementClass: EFTimeDisplay,
7
+ react: React
8
8
  });
9
- export {
10
- TimeDisplay
11
- };
9
+ export { TimeDisplay };
@@ -1,128 +1,120 @@
1
- /**
2
- * @license
3
- * Copyright 2018 Google LLC
4
- * SPDX-License-Identifier: BSD-3-Clause
5
- */
6
- const reservedReactProperties = /* @__PURE__ */ new Set([
7
- "id",
8
- "children",
9
- "localName",
10
- "ref",
11
- "style",
12
- "className"
1
+ const NODE_MODE = false;
2
+ const DEV_MODE = true;
3
+ const reservedReactProperties = new Set([
4
+ "id",
5
+ "children",
6
+ "localName",
7
+ "ref",
8
+ "style",
9
+ "className"
13
10
  ]);
14
11
  const listenedEvents = /* @__PURE__ */ new WeakMap();
12
+ /**
13
+ * Adds an event listener for the specified event to the given node. In the
14
+ * React setup, there should only ever be one event listener. Thus, for
15
+ * efficiency only one listener is added and the handler for that listener is
16
+ * updated to point to the given listener function.
17
+ */
15
18
  const addOrUpdateEventListener = (node, event, listener) => {
16
- let events = listenedEvents.get(node);
17
- if (events === void 0) {
18
- listenedEvents.set(node, events = /* @__PURE__ */ new Map());
19
- }
20
- let handler = events.get(event);
21
- if (listener !== void 0) {
22
- if (handler === void 0) {
23
- events.set(event, handler = { handleEvent: listener });
24
- node.addEventListener(event, handler);
25
- } else {
26
- handler.handleEvent = listener;
27
- }
28
- } else if (handler !== void 0) {
29
- events.delete(event);
30
- node.removeEventListener(event, handler);
31
- }
19
+ let events = listenedEvents.get(node);
20
+ if (events === void 0) listenedEvents.set(node, events = /* @__PURE__ */ new Map());
21
+ let handler = events.get(event);
22
+ if (listener !== void 0) if (handler === void 0) {
23
+ events.set(event, handler = { handleEvent: listener });
24
+ node.addEventListener(event, handler);
25
+ } else handler.handleEvent = listener;
26
+ else if (handler !== void 0) {
27
+ events.delete(event);
28
+ node.removeEventListener(event, handler);
29
+ }
32
30
  };
31
+ /**
32
+ * Sets properties and events on custom elements. These properties and events
33
+ * have been pre-filtered so we know they should apply to the custom element.
34
+ */
33
35
  const setProperty = (node, name, value, old, events) => {
34
- const event = events?.[name];
35
- if (event !== void 0) {
36
- if (value !== old) {
37
- addOrUpdateEventListener(node, event, value);
38
- }
39
- return;
40
- }
41
- node[name] = value;
42
- if ((value === void 0 || value === null) && name in HTMLElement.prototype) {
43
- node.removeAttribute(name);
44
- }
36
+ const event = events?.[name];
37
+ if (event !== void 0) {
38
+ if (value !== old) addOrUpdateEventListener(node, event, value);
39
+ return;
40
+ }
41
+ node[name] = value;
42
+ if ((value === void 0 || value === null) && name in HTMLElement.prototype) node.removeAttribute(name);
45
43
  };
46
- const createComponent = ({
47
- react: React,
48
- tagName,
49
- elementClass,
50
- events,
51
- displayName
52
- }) => {
53
- const eventProps = new Set(Object.keys(events ?? {}));
54
- {
55
- for (const p of reservedReactProperties) {
56
- if (p in elementClass.prototype && !(p in HTMLElement.prototype)) {
57
- console.warn(
58
- `${tagName} contains property ${p} which is a React reserved property. It will be used by React and not set on the element.`
59
- );
60
- }
61
- }
62
- }
63
- const ReactComponent = React.forwardRef((props, ref) => {
64
- const prevElemPropsRef = React.useRef(/* @__PURE__ */ new Map());
65
- const elementRef = React.useRef(null);
66
- const reactProps = {};
67
- const elementProps = {};
68
- for (const [k, v] of Object.entries(props)) {
69
- if (reservedReactProperties.has(k)) {
70
- reactProps[k === "className" ? "class" : k] = v;
71
- continue;
72
- }
73
- if (eventProps.has(k) || k in elementClass.prototype) {
74
- elementProps[k] = v;
75
- continue;
76
- }
77
- reactProps[k] = v;
78
- }
79
- {
80
- React.useLayoutEffect(() => {
81
- if (elementRef.current === null) {
82
- return;
83
- }
84
- const newElemProps = /* @__PURE__ */ new Map();
85
- for (const key in elementProps) {
86
- setProperty(
87
- elementRef.current,
88
- key,
89
- props[key],
90
- prevElemPropsRef.current.get(key),
91
- events
92
- );
93
- prevElemPropsRef.current.delete(key);
94
- newElemProps.set(key, props[key]);
95
- }
96
- for (const [key, value] of prevElemPropsRef.current) {
97
- setProperty(elementRef.current, key, void 0, value, events);
98
- }
99
- prevElemPropsRef.current = newElemProps;
100
- });
101
- React.useLayoutEffect(() => {
102
- elementRef.current?.removeAttribute("defer-hydration");
103
- }, []);
104
- }
105
- {
106
- reactProps.suppressHydrationWarning = true;
107
- }
108
- return React.createElement(tagName, {
109
- ...reactProps,
110
- ref: React.useCallback(
111
- (node) => {
112
- elementRef.current = node;
113
- if (typeof ref === "function") {
114
- ref(node);
115
- } else if (ref !== null) {
116
- ref.current = node;
117
- }
118
- },
119
- [ref]
120
- )
121
- });
122
- });
123
- ReactComponent.displayName = displayName ?? elementClass.name;
124
- return ReactComponent;
125
- };
126
- export {
127
- createComponent
44
+ /**
45
+ * Creates a React component for a custom element. Properties are distinguished
46
+ * from attributes automatically, and events can be configured so they are added
47
+ * to the custom element as event listeners.
48
+ *
49
+ * @param options An options bag containing the parameters needed to generate a
50
+ * wrapped web component.
51
+ *
52
+ * @param options.react The React module, typically imported from the `react`
53
+ * npm package.
54
+ * @param options.tagName The custom element tag name registered via
55
+ * `customElements.define`.
56
+ * @param options.elementClass The custom element class registered via
57
+ * `customElements.define`.
58
+ * @param options.events An object listing events to which the component can
59
+ * listen. The object keys are the event property names passed in via React
60
+ * props and the object values are the names of the corresponding events
61
+ * generated by the custom element. For example, given `{onactivate:
62
+ * 'activate'}` an event function may be passed via the component's `onactivate`
63
+ * prop and will be called when the custom element fires its `activate` event.
64
+ * @param options.displayName A React component display name, used in debugging
65
+ * messages. Default value is inferred from the name of custom element class
66
+ * registered via `customElements.define`.
67
+ */
68
+ const createComponent = ({ react: React, tagName, elementClass, events, displayName }) => {
69
+ const eventProps = new Set(Object.keys(events ?? {}));
70
+ if (DEV_MODE) {
71
+ for (const p of reservedReactProperties) if (p in elementClass.prototype && !(p in HTMLElement.prototype)) console.warn(`${tagName} contains property ${p} which is a React reserved property. It will be used by React and not set on the element.`);
72
+ }
73
+ const ReactComponent = React.forwardRef((props, ref) => {
74
+ const prevElemPropsRef = React.useRef(/* @__PURE__ */ new Map());
75
+ const elementRef = React.useRef(null);
76
+ const reactProps = {};
77
+ const elementProps = {};
78
+ for (const [k, v] of Object.entries(props)) {
79
+ if (reservedReactProperties.has(k)) {
80
+ reactProps[k === "className" ? "class" : k] = v;
81
+ continue;
82
+ }
83
+ if (eventProps.has(k) || k in elementClass.prototype) {
84
+ elementProps[k] = v;
85
+ continue;
86
+ }
87
+ reactProps[k] = v;
88
+ }
89
+ if (!NODE_MODE) {
90
+ React.useLayoutEffect(() => {
91
+ if (elementRef.current === null) return;
92
+ const newElemProps = /* @__PURE__ */ new Map();
93
+ for (const key in elementProps) {
94
+ setProperty(elementRef.current, key, props[key], prevElemPropsRef.current.get(key), events);
95
+ prevElemPropsRef.current.delete(key);
96
+ newElemProps.set(key, props[key]);
97
+ }
98
+ for (const [key, value] of prevElemPropsRef.current) setProperty(elementRef.current, key, void 0, value, events);
99
+ prevElemPropsRef.current = newElemProps;
100
+ });
101
+ React.useLayoutEffect(() => {
102
+ elementRef.current?.removeAttribute("defer-hydration");
103
+ }, []);
104
+ }
105
+ if (NODE_MODE) {
106
+ if ((React.createElement.name === "litPatchedCreateElement" || globalThis.litSsrReactEnabled) && Object.keys(elementProps).length) reactProps._$litProps$ = elementProps;
107
+ } else reactProps.suppressHydrationWarning = true;
108
+ return React.createElement(tagName, {
109
+ ...reactProps,
110
+ ref: React.useCallback((node) => {
111
+ elementRef.current = node;
112
+ if (typeof ref === "function") ref(node);
113
+ else if (ref !== null) ref.current = node;
114
+ }, [ref])
115
+ });
116
+ });
117
+ ReactComponent.displayName = displayName ?? elementClass.name;
118
+ return ReactComponent;
128
119
  };
120
+ export { createComponent };
@@ -2,10 +2,8 @@ import React from "react";
2
2
  import { createComponent } from "@lit/react";
3
3
  import { EFAudio } from "@editframe/elements";
4
4
  const Audio = createComponent({
5
- tagName: "ef-audio",
6
- elementClass: EFAudio,
7
- react: React
5
+ tagName: "ef-audio",
6
+ elementClass: EFAudio,
7
+ react: React
8
8
  });
9
- export {
10
- Audio
11
- };
9
+ export { Audio };
@@ -1,35 +1,29 @@
1
- import { EFCaptions, EFCaptionsActiveWord, EFCaptionsSegment, EFCaptionsBeforeActiveWord, EFCaptionsAfterActiveWord } from "@editframe/elements";
2
- import { createComponent } from "@lit/react";
3
1
  import React from "react";
2
+ import { createComponent } from "@lit/react";
3
+ import { EFCaptions, EFCaptionsActiveWord, EFCaptionsAfterActiveWord, EFCaptionsBeforeActiveWord, EFCaptionsSegment } from "@editframe/elements";
4
4
  const Captions = createComponent({
5
- tagName: "ef-captions",
6
- elementClass: EFCaptions,
7
- react: React
5
+ tagName: "ef-captions",
6
+ elementClass: EFCaptions,
7
+ react: React
8
8
  });
9
9
  const CaptionsActiveWord = createComponent({
10
- tagName: "ef-captions-active-word",
11
- elementClass: EFCaptionsActiveWord,
12
- react: React
10
+ tagName: "ef-captions-active-word",
11
+ elementClass: EFCaptionsActiveWord,
12
+ react: React
13
13
  });
14
14
  const CaptionsSegment = createComponent({
15
- tagName: "ef-captions-segment",
16
- elementClass: EFCaptionsSegment,
17
- react: React
15
+ tagName: "ef-captions-segment",
16
+ elementClass: EFCaptionsSegment,
17
+ react: React
18
18
  });
19
19
  const CaptionsBeforeActiveWord = createComponent({
20
- tagName: "ef-captions-before-active-word",
21
- elementClass: EFCaptionsBeforeActiveWord,
22
- react: React
20
+ tagName: "ef-captions-before-active-word",
21
+ elementClass: EFCaptionsBeforeActiveWord,
22
+ react: React
23
23
  });
24
24
  const CaptionsAfterActiveWord = createComponent({
25
- tagName: "ef-captions-after-active-word",
26
- elementClass: EFCaptionsAfterActiveWord,
27
- react: React
25
+ tagName: "ef-captions-after-active-word",
26
+ elementClass: EFCaptionsAfterActiveWord,
27
+ react: React
28
28
  });
29
- export {
30
- Captions,
31
- CaptionsActiveWord,
32
- CaptionsAfterActiveWord,
33
- CaptionsBeforeActiveWord,
34
- CaptionsSegment
35
- };
29
+ export { Captions, CaptionsActiveWord, CaptionsAfterActiveWord, CaptionsBeforeActiveWord, CaptionsSegment };
@@ -2,10 +2,8 @@ import React from "react";
2
2
  import { createComponent } from "@lit/react";
3
3
  import { EFImage } from "@editframe/elements";
4
4
  const Image = createComponent({
5
- tagName: "ef-image",
6
- elementClass: EFImage,
7
- react: React
5
+ tagName: "ef-image",
6
+ elementClass: EFImage,
7
+ react: React
8
8
  });
9
- export {
10
- Image
11
- };
9
+ export { Image };
@@ -1,11 +1,9 @@
1
- import { EFTimegroup } from "@editframe/elements";
2
- import React from "react";
3
1
  import { createComponent } from "../create-component.js";
2
+ import React from "react";
3
+ import { EFTimegroup } from "@editframe/elements";
4
4
  const Timegroup = createComponent({
5
- tagName: "ef-timegroup",
6
- elementClass: EFTimegroup,
7
- react: React
5
+ tagName: "ef-timegroup",
6
+ elementClass: EFTimegroup,
7
+ react: React
8
8
  });
9
- export {
10
- Timegroup
11
- };
9
+ export { Timegroup };
@@ -2,10 +2,8 @@ import React from "react";
2
2
  import { createComponent } from "@lit/react";
3
3
  import { EFVideo } from "@editframe/elements";
4
4
  const Video = createComponent({
5
- tagName: "ef-video",
6
- elementClass: EFVideo,
7
- react: React
5
+ tagName: "ef-video",
6
+ elementClass: EFVideo,
7
+ react: React
8
8
  });
9
- export {
10
- Video
11
- };
9
+ export { Video };
@@ -2,10 +2,8 @@ import React from "react";
2
2
  import { createComponent } from "@lit/react";
3
3
  import { EFWaveform } from "@editframe/elements";
4
4
  const Waveform = createComponent({
5
- tagName: "ef-waveform",
6
- elementClass: EFWaveform,
7
- react: React
5
+ tagName: "ef-waveform",
6
+ elementClass: EFWaveform,
7
+ react: React
8
8
  });
9
- export {
10
- Waveform
11
- };
9
+ export { Waveform };
@@ -1,11 +1,9 @@
1
- import { EFConfiguration } from "@editframe/elements";
2
- import React from "react";
3
1
  import { createComponent } from "../create-component.js";
2
+ import React from "react";
3
+ import { EFConfiguration } from "@editframe/elements";
4
4
  const Configuration = createComponent({
5
- tagName: "ef-configuration",
6
- elementClass: EFConfiguration,
7
- react: React
5
+ tagName: "ef-configuration",
6
+ elementClass: EFConfiguration,
7
+ react: React
8
8
  });
9
- export {
10
- Configuration
11
- };
9
+ export { Configuration };
@@ -2,10 +2,8 @@ import React from "react";
2
2
  import { createComponent } from "@lit/react";
3
3
  import { EFFilmstrip } from "@editframe/elements";
4
4
  const Filmstrip = createComponent({
5
- tagName: "ef-filmstrip",
6
- elementClass: EFFilmstrip,
7
- react: React
5
+ tagName: "ef-filmstrip",
6
+ elementClass: EFFilmstrip,
7
+ react: React
8
8
  });
9
- export {
10
- Filmstrip
11
- };
9
+ export { Filmstrip };
@@ -1,11 +1,9 @@
1
- import { EFFitScale } from "@editframe/elements";
2
- import { createComponent } from "@lit/react";
3
1
  import React from "react";
2
+ import { createComponent } from "@lit/react";
3
+ import { EFFitScale } from "@editframe/elements";
4
4
  const FitScale = createComponent({
5
- tagName: "ef-fit-scale",
6
- elementClass: EFFitScale,
7
- react: React
5
+ tagName: "ef-fit-scale",
6
+ elementClass: EFFitScale,
7
+ react: React
8
8
  });
9
- export {
10
- FitScale
11
- };
9
+ export { FitScale };
@@ -1,11 +1,9 @@
1
- import { EFFocusOverlay } from "@editframe/elements";
2
- import { createComponent } from "@lit/react";
3
1
  import React from "react";
2
+ import { createComponent } from "@lit/react";
3
+ import { EFFocusOverlay } from "@editframe/elements";
4
4
  const FocusOverlay = createComponent({
5
- tagName: "ef-focus-overlay",
6
- elementClass: EFFocusOverlay,
7
- react: React
5
+ tagName: "ef-focus-overlay",
6
+ elementClass: EFFocusOverlay,
7
+ react: React
8
8
  });
9
- export {
10
- FocusOverlay
11
- };
9
+ export { FocusOverlay };
@@ -1,11 +1,9 @@
1
- import { EFPreview } from "@editframe/elements";
2
- import { createComponent } from "@lit/react";
3
1
  import React from "react";
2
+ import { createComponent } from "@lit/react";
3
+ import { EFPreview } from "@editframe/elements";
4
4
  const Preview = createComponent({
5
- tagName: "ef-preview",
6
- elementClass: EFPreview,
7
- react: React
5
+ tagName: "ef-preview",
6
+ elementClass: EFPreview,
7
+ react: React
8
8
  });
9
- export {
10
- Preview
11
- };
9
+ export { Preview };
@@ -1,11 +1,9 @@
1
- import { EFScrubber } from "@editframe/elements";
2
- import { createComponent } from "@lit/react";
3
1
  import React from "react";
2
+ import { createComponent } from "@lit/react";
3
+ import { EFScrubber } from "@editframe/elements";
4
4
  const Scrubber = createComponent({
5
- tagName: "ef-scrubber",
6
- elementClass: EFScrubber,
7
- react: React
5
+ tagName: "ef-scrubber",
6
+ elementClass: EFScrubber,
7
+ react: React
8
8
  });
9
- export {
10
- Scrubber
11
- };
9
+ export { Scrubber };
@@ -2,10 +2,8 @@ import React from "react";
2
2
  import { createComponent } from "@lit/react";
3
3
  import { EFToggleLoop } from "@editframe/elements";
4
4
  const ToggleLoop = createComponent({
5
- tagName: "ef-toggle-loop",
6
- elementClass: EFToggleLoop,
7
- react: React
5
+ tagName: "ef-toggle-loop",
6
+ elementClass: EFToggleLoop,
7
+ react: React
8
8
  });
9
- export {
10
- ToggleLoop
11
- };
9
+ export { ToggleLoop };
@@ -2,10 +2,8 @@ import React from "react";
2
2
  import { createComponent } from "@lit/react";
3
3
  import { EFTogglePlay } from "@editframe/elements";
4
4
  const TogglePlay = createComponent({
5
- tagName: "ef-toggle-play",
6
- elementClass: EFTogglePlay,
7
- react: React
5
+ tagName: "ef-toggle-play",
6
+ elementClass: EFTogglePlay,
7
+ react: React
8
8
  });
9
- export {
10
- TogglePlay
11
- };
9
+ export { TogglePlay };
@@ -2,10 +2,8 @@ import React from "react";
2
2
  import { createComponent } from "@lit/react";
3
3
  import { EFWorkbench } from "@editframe/elements";
4
4
  const Workbench = createComponent({
5
- tagName: "ef-workbench",
6
- elementClass: EFWorkbench,
7
- react: React
5
+ tagName: "ef-workbench",
6
+ elementClass: EFWorkbench,
7
+ react: React
8
8
  });
9
- export {
10
- Workbench
11
- };
9
+ export { Workbench };
@@ -1,35 +1,34 @@
1
- import { useRef, useState, useEffect } from "react";
2
- class CurrentTimeController {
3
- constructor(host, setCurrentTime) {
4
- this.host = host;
5
- this.setCurrentTime = setCurrentTime;
6
- this.host.addController(this);
7
- }
8
- hostDisconnected() {
9
- this.host.removeController(this);
10
- }
11
- hostUpdated() {
12
- this.setCurrentTime({
13
- ownCurrentTimeMs: this.host.ownCurrentTimeMs,
14
- durationMs: this.host.durationMs,
15
- percentComplete: this.host.ownCurrentTimeMs / this.host.durationMs
16
- });
17
- }
18
- }
19
- const useTimingInfo = (timegroupRef = useRef(null)) => {
20
- const [timeInfo, setTimeInfo] = useState({
21
- ownCurrentTimeMs: 0,
22
- durationMs: 0,
23
- percentComplete: 0
24
- });
25
- useEffect(() => {
26
- if (!timegroupRef.current) {
27
- throw new Error("Timegroup ref not set");
28
- }
29
- new CurrentTimeController(timegroupRef.current, setTimeInfo);
30
- }, [timegroupRef.current]);
31
- return { ...timeInfo, ref: timegroupRef };
1
+ import { useEffect, useRef, useState } from "react";
2
+ var CurrentTimeController = class {
3
+ constructor(host, setCurrentTime) {
4
+ this.host = host;
5
+ this.setCurrentTime = setCurrentTime;
6
+ this.host.addController(this);
7
+ }
8
+ hostDisconnected() {
9
+ this.host.removeController(this);
10
+ }
11
+ hostUpdated() {
12
+ this.setCurrentTime({
13
+ ownCurrentTimeMs: this.host.ownCurrentTimeMs,
14
+ durationMs: this.host.durationMs,
15
+ percentComplete: this.host.ownCurrentTimeMs / this.host.durationMs
16
+ });
17
+ }
32
18
  };
33
- export {
34
- useTimingInfo
19
+ const useTimingInfo = (timegroupRef = useRef(null)) => {
20
+ const [timeInfo, setTimeInfo] = useState({
21
+ ownCurrentTimeMs: 0,
22
+ durationMs: 0,
23
+ percentComplete: 0
24
+ });
25
+ useEffect(() => {
26
+ if (!timegroupRef.current) throw new Error("Timegroup ref not set");
27
+ new CurrentTimeController(timegroupRef.current, setTimeInfo);
28
+ }, [timegroupRef.current]);
29
+ return {
30
+ ...timeInfo,
31
+ ref: timegroupRef
32
+ };
35
33
  };
34
+ export { useTimingInfo };
package/dist/index.js CHANGED
@@ -15,26 +15,4 @@ import { ToggleLoop } from "./gui/ToggleLoop.js";
15
15
  import { Scrubber } from "./gui/Scrubber.js";
16
16
  import { useTimingInfo } from "./hooks/useTimingInfo.js";
17
17
  import { TimeDisplay } from "./components/TimeDisplay.js";
18
- export {
19
- Audio,
20
- Captions,
21
- CaptionsActiveWord,
22
- CaptionsAfterActiveWord,
23
- CaptionsBeforeActiveWord,
24
- CaptionsSegment,
25
- Configuration,
26
- Filmstrip,
27
- FitScale,
28
- FocusOverlay,
29
- Image,
30
- Preview,
31
- Scrubber,
32
- TimeDisplay,
33
- Timegroup,
34
- ToggleLoop,
35
- TogglePlay,
36
- Video,
37
- Waveform,
38
- Workbench,
39
- useTimingInfo
40
- };
18
+ export { Audio, Captions, CaptionsActiveWord, CaptionsAfterActiveWord, CaptionsBeforeActiveWord, CaptionsSegment, Configuration, Filmstrip, FitScale, FocusOverlay, Image, Preview, Scrubber, TimeDisplay, Timegroup, ToggleLoop, TogglePlay, Video, Waveform, Workbench, useTimingInfo };