@floegence/redevplugin-ui 0.4.3 → 0.5.1

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.
@@ -2,6 +2,6 @@ export * from "./contracts.gen.js";
2
2
  export * from "./errors.js";
3
3
  export * from "./platform.js";
4
4
  export { PluginSurfaceScope, createPluginSurfaceScope } from "./surface-scope.js";
5
- export { PluginSurfaceHost, PluginSurfaceReloadLimiter, createReDevPluginSurfaceTransport, defaultPluginSurfaceReloadMax, defaultPluginSurfaceReloadWindowMs, isPluginRiskPlan, opaqueSurfaceDocumentSchemaVersion, pluginRiskPlanSchemaVersion, trustedParentBridgeHandshakeTranscriptSHA256, } from "./surface.js";
6
- export type { BridgeLifecycleEvent, MessageChannelLike, MessageEventLike, MessagePortLike, OpaqueSurfaceAsset, OpaqueSurfaceDocument, OpaqueSurfaceStyle, OpaqueSurfaceWorker, PluginConfirmationDecision, PluginConfirmationHandler, PluginConfirmationIntent, PluginConfirmationPlan, PluginMethodResult, PluginRiskEffect, PluginRiskFlag, PluginRiskPlan, PluginRiskSeverity, PluginStreamEvent, PluginSurfaceHostBootstrap, PluginSurfaceHostOptions, PluginSurfaceOpeningProgress, PluginSurfacePreparationResult, PluginSurfaceReloadDecision, PluginSurfaceReloadLimiterOptions, PluginSurfaceReloadState, PluginTrustedMethodResult, ReDevPluginSurfaceTransport, ReDevPluginSurfaceTransportOptions, TrustedParentBridgeHandshake, TrustedParentBridgeTokenRequest, WindowLike, } from "./surface.js";
7
- export type { FetchInitLike, FetchLike, FetchResponseLike, HostEnvelope } from "./http.js";
5
+ export { PluginSurfaceReloadLimiter, PluginSurfaceSlot, createReDevPluginSurfaceTransport, defaultPluginSurfaceReloadMax, defaultPluginSurfaceReloadWindowMs, isPluginRiskPlan, opaqueSurfaceDocumentSchemaVersion, pluginRiskPlanSchemaVersion, trustedParentBridgeHandshakeTranscriptSHA256, } from "./surface.js";
6
+ export type { BridgeLifecycleEvent, MessageChannelLike, MessageEventLike, MessagePortLike, OpaqueSurfaceAsset, OpaqueSurfaceDocument, OpaqueSurfaceStyle, OpaqueSurfaceWorker, PluginConfirmationDecision, PluginConfirmationHandler, PluginConfirmationIntent, PluginConfirmationPlan, PluginMethodResult, PluginRiskEffect, PluginRiskFlag, PluginRiskPlan, PluginRiskSeverity, PluginStreamEvent, PluginSurfaceHost, PluginSurfaceCloseResult, PluginSurfaceOpeningProgress, PluginSurfaceQuiesceResult, PluginSurfacePreparationResult, PluginSurfaceReloadDecision, PluginSurfaceReloadLimiterOptions, PluginSurfaceReloadState, PluginSurfaceSlotOptions, PluginSurfaceSlotState, PluginTrustedMethodResult, ReDevPluginSurfaceTransport, ReDevPluginSurfaceTransportOptions, TrustedParentBridgeHandshake, TrustedParentBridgeTokenRequest, WindowLike, } from "./surface.js";
7
+ export type { FetchInitLike, FetchLike, FetchResponseLike, PlatformResponse } from "./http.js";
@@ -2,4 +2,4 @@ export * from "./contracts.gen.js";
2
2
  export * from "./errors.js";
3
3
  export * from "./platform.js";
4
4
  export { PluginSurfaceScope, createPluginSurfaceScope } from "./surface-scope.js";
5
- export { PluginSurfaceHost, PluginSurfaceReloadLimiter, createReDevPluginSurfaceTransport, defaultPluginSurfaceReloadMax, defaultPluginSurfaceReloadWindowMs, isPluginRiskPlan, opaqueSurfaceDocumentSchemaVersion, pluginRiskPlanSchemaVersion, trustedParentBridgeHandshakeTranscriptSHA256, } from "./surface.js";
5
+ export { PluginSurfaceReloadLimiter, PluginSurfaceSlot, createReDevPluginSurfaceTransport, defaultPluginSurfaceReloadMax, defaultPluginSurfaceReloadWindowMs, isPluginRiskPlan, opaqueSurfaceDocumentSchemaVersion, pluginRiskPlanSchemaVersion, trustedParentBridgeHandshakeTranscriptSHA256, } from "./surface.js";
@@ -0,0 +1,67 @@
1
+ import { type OpaqueSurfaceAllowedTag } from "./opaque-surface-policy.gen.js";
2
+ export type PluginUIAttributeValue = string | number | boolean;
3
+ export type PluginUITextVNode = {
4
+ type: "text";
5
+ key: string;
6
+ text: string;
7
+ };
8
+ export type PluginUIElementVNode = {
9
+ type: "element";
10
+ key: string;
11
+ tag: OpaqueSurfaceAllowedTag;
12
+ attributes?: Record<string, PluginUIAttributeValue>;
13
+ children?: PluginUIVNode[];
14
+ };
15
+ export type PluginUIVNode = PluginUITextVNode | PluginUIElementVNode;
16
+ export type PluginUISetTextOperation = {
17
+ type: "set_text";
18
+ target_key: string;
19
+ text: string;
20
+ };
21
+ export type PluginUIPatchAttributesOperation = {
22
+ type: "patch_attributes";
23
+ target_key: string;
24
+ set: Record<string, PluginUIAttributeValue>;
25
+ remove: string[];
26
+ };
27
+ export type PluginUIPatchControlOperation = {
28
+ type: "patch_control";
29
+ target_key: string;
30
+ edit_revision: number;
31
+ value?: string | null;
32
+ checked?: boolean | null;
33
+ };
34
+ export type PluginUIInsertChildOperation = {
35
+ type: "insert_child";
36
+ parent_key: string;
37
+ before_key: string | null;
38
+ node: PluginUIVNode;
39
+ };
40
+ export type PluginUIRemoveChildOperation = {
41
+ type: "remove_child";
42
+ target_key: string;
43
+ };
44
+ export type PluginUIMoveChildOperation = {
45
+ type: "move_child";
46
+ target_key: string;
47
+ parent_key: string;
48
+ before_key: string | null;
49
+ };
50
+ export type PluginUIPatchOperation = PluginUISetTextOperation | PluginUIPatchAttributesOperation | PluginUIPatchControlOperation | PluginUIInsertChildOperation | PluginUIRemoveChildOperation | PluginUIMoveChildOperation;
51
+ export type PluginUIMountMessage = {
52
+ type: "redevplugin.ui.mount";
53
+ id: string;
54
+ revision: 1;
55
+ tree: PluginUIElementVNode;
56
+ };
57
+ export type PluginUIPatchMessage = {
58
+ type: "redevplugin.ui.patch";
59
+ id: string;
60
+ base_revision: number;
61
+ revision: number;
62
+ operations: PluginUIPatchOperation[];
63
+ };
64
+ export declare class PluginUIReconcileError extends Error {
65
+ constructor(message: string);
66
+ }
67
+ export declare function validatePluginUITree(tree: PluginUIVNode): PluginUIElementVNode;
@@ -0,0 +1,125 @@
1
+ import { opaqueSurfaceAllowedTags, opaqueSurfaceGlobalAttributes, opaqueSurfaceRenderLimits, opaqueSurfaceSafeInputTypes, opaqueSurfaceTagAttributes, } from "./opaque-surface-policy.gen.js";
2
+ export class PluginUIReconcileError extends Error {
3
+ constructor(message) {
4
+ super(message);
5
+ this.name = "PluginUIReconcileError";
6
+ }
7
+ }
8
+ const keyPattern = new RegExp("^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$");
9
+ const identifierPattern = new RegExp("^[A-Za-z0-9._:-]{1,128}$");
10
+ const opaqueHandlePattern = new RegExp("^[A-Za-z0-9_-]{8,160}$");
11
+ const allowedTags = new Set(opaqueSurfaceAllowedTags);
12
+ const globalAttributes = new Set(opaqueSurfaceGlobalAttributes);
13
+ const safeInputTypes = new Set(opaqueSurfaceSafeInputTypes);
14
+ const textNodeKeys = new Set(["type", "key", "text"]);
15
+ const elementNodeKeys = new Set(["type", "key", "tag", "attributes", "children"]);
16
+ const tagAttributes = new Map(Object.entries(opaqueSurfaceTagAttributes).map(([tag, attributes]) => [tag, new Set(attributes)]));
17
+ export function validatePluginUITree(tree) {
18
+ if (!isElement(tree)) {
19
+ throw new PluginUIReconcileError("Plugin UI root must be one keyed element");
20
+ }
21
+ const keys = new Set();
22
+ const ancestors = new Set();
23
+ let nodes = 0;
24
+ const visit = (node, depth) => {
25
+ nodes += 1;
26
+ if (nodes > opaqueSurfaceRenderLimits.max_render_nodes || depth > opaqueSurfaceRenderLimits.max_render_depth) {
27
+ throw new PluginUIReconcileError("Plugin UI tree exceeds structural limits");
28
+ }
29
+ if ((!isText(node) && !isElement(node)) || ancestors.has(node)) {
30
+ throw new PluginUIReconcileError("Plugin UI tree must contain plain keyed acyclic VNodes");
31
+ }
32
+ if (!keyPattern.test(node.key) || keys.has(node.key)) {
33
+ throw new PluginUIReconcileError(`Plugin UI key is invalid or duplicated: ${String(node.key)}`);
34
+ }
35
+ keys.add(node.key);
36
+ if (node.type === "text") {
37
+ if (node.text.length > opaqueSurfaceRenderLimits.max_text_length) {
38
+ throw new PluginUIReconcileError("Plugin UI text exceeds limits");
39
+ }
40
+ return;
41
+ }
42
+ ancestors.add(node);
43
+ try {
44
+ if (!allowedTags.has(node.tag)) {
45
+ throw new PluginUIReconcileError(`Plugin UI tag is not allowed for ${node.key}`);
46
+ }
47
+ if (node.attributes !== undefined) {
48
+ if (!isPlainRecord(node.attributes) || Object.keys(node.attributes).length > opaqueSurfaceRenderLimits.max_attributes_per_element) {
49
+ throw new PluginUIReconcileError(`Plugin UI attributes are invalid for ${node.key}`);
50
+ }
51
+ for (const [name, value] of Object.entries(node.attributes)) {
52
+ if (!validAttribute(node.tag, name, value)) {
53
+ throw new PluginUIReconcileError(`Plugin UI attribute ${name} is not allowed for ${node.key}`);
54
+ }
55
+ }
56
+ }
57
+ if (node.children !== undefined) {
58
+ if (!Array.isArray(node.children))
59
+ throw new PluginUIReconcileError(`Plugin UI children are invalid for ${node.key}`);
60
+ for (const child of node.children)
61
+ visit(child, depth + 1);
62
+ }
63
+ }
64
+ finally {
65
+ ancestors.delete(node);
66
+ }
67
+ };
68
+ visit(tree, 1);
69
+ return tree;
70
+ }
71
+ function isText(value) {
72
+ return isPlainRecord(value) && hasExactKeys(value, textNodeKeys) &&
73
+ value.type === "text" && typeof value.key === "string" && typeof value.text === "string";
74
+ }
75
+ function isElement(value) {
76
+ if (!isPlainRecord(value))
77
+ return false;
78
+ return hasAllowedKeys(value, elementNodeKeys) &&
79
+ value.type === "element" && typeof value.key === "string" && typeof value.tag === "string";
80
+ }
81
+ function hasExactKeys(value, keys) {
82
+ const actual = Object.keys(value);
83
+ return actual.length === keys.size && actual.every((key) => keys.has(key));
84
+ }
85
+ function hasAllowedKeys(value, keys) {
86
+ return Object.keys(value).every((key) => keys.has(key));
87
+ }
88
+ function isPlainRecord(value) {
89
+ if (value === null || typeof value !== "object" || Array.isArray(value))
90
+ return false;
91
+ const prototype = Object.getPrototypeOf(value);
92
+ return prototype === Object.prototype || prototype === null;
93
+ }
94
+ function validAttribute(tag, name, value) {
95
+ const normalized = name.toLowerCase();
96
+ if (normalized.startsWith("on") || ["style", "src", "srcset", "href", "srcdoc", "action", "formaction"].includes(normalized)) {
97
+ return false;
98
+ }
99
+ if (!globalAttributes.has(normalized) && !normalized.startsWith("aria-") && !tagAttributes.get(tag)?.has(normalized)) {
100
+ return false;
101
+ }
102
+ if (typeof value !== "string" && typeof value !== "number" && typeof value !== "boolean")
103
+ return false;
104
+ if (typeof value === "number" && !Number.isFinite(value))
105
+ return false;
106
+ const serialized = String(value);
107
+ if (normalized === "data-redevplugin-action" || normalized === "data-redevplugin-escape-action") {
108
+ if (!identifierPattern.test(serialized))
109
+ return false;
110
+ }
111
+ if (normalized === "data-redevplugin-asset-binding") {
112
+ if (!serialized.startsWith("asset_") || !opaqueHandlePattern.test(serialized))
113
+ return false;
114
+ }
115
+ if (normalized === "data-redevplugin-asset-attr" && serialized !== "src" && serialized !== "poster")
116
+ return false;
117
+ if (normalized === "data-redevplugin-canvas" && (tag !== "canvas" || !keyPattern.test(serialized)))
118
+ return false;
119
+ if (tag === "canvas" && (normalized === "width" || normalized === "height") &&
120
+ (!/^[1-9][0-9]{0,4}$/.test(serialized) || Number(serialized) > opaqueSurfaceRenderLimits.max_canvas_dimension))
121
+ return false;
122
+ if (tag === "input" && normalized === "type" && !safeInputTypes.has(serialized.trim().toLowerCase() || "text"))
123
+ return false;
124
+ return serialized.length <= opaqueSurfaceRenderLimits.max_attribute_value_length;
125
+ }
@@ -0,0 +1,10 @@
1
+ import { type PluginUIElementVNode, type PluginUIPatchOperation } from "./ui-patch-validator.js";
2
+ export { PluginUIReconcileError, validatePluginUITree } from "./ui-patch-validator.js";
3
+ export type { PluginUIAttributeValue, PluginUIElementVNode, PluginUIInsertChildOperation, PluginUIMountMessage, PluginUIMoveChildOperation, PluginUIPatchAttributesOperation, PluginUIPatchControlOperation, PluginUIPatchMessage, PluginUIPatchOperation, PluginUIRemoveChildOperation, PluginUISetTextOperation, PluginUITextVNode, PluginUIVNode, } from "./ui-patch-validator.js";
4
+ export type PluginUIReconcileOptions = {
5
+ controlEditRevisions?: ReadonlyMap<string, number>;
6
+ transferredCanvasKeys?: ReadonlySet<string>;
7
+ maxOperations?: number;
8
+ };
9
+ export declare function reconcilePluginUITrees(current: PluginUIElementVNode, next: PluginUIElementVNode, options?: PluginUIReconcileOptions): PluginUIPatchOperation[];
10
+ export declare function reconcileValidatedPluginUITrees(current: PluginUIElementVNode, next: PluginUIElementVNode, options?: PluginUIReconcileOptions): PluginUIPatchOperation[];
@@ -0,0 +1,283 @@
1
+ import { opaqueSurfaceRenderLimits } from "./opaque-surface-policy.gen.js";
2
+ import { PluginUIReconcileError, validatePluginUITree, } from "./ui-patch-validator.js";
3
+ export { PluginUIReconcileError, validatePluginUITree } from "./ui-patch-validator.js";
4
+ const editableValueTags = new Set(["input", "textarea", "select", "option"]);
5
+ const emptyAttributes = {};
6
+ const maxPluginUIPatchOperations = opaqueSurfaceRenderLimits.max_patch_operations;
7
+ export function reconcilePluginUITrees(current, next, options = {}) {
8
+ validatePluginUITree(current);
9
+ validatePluginUITree(next);
10
+ return reconcileValidatedPluginUITrees(current, next, options);
11
+ }
12
+ // Internal fast path for callers that retain trees returned by validatePluginUITree.
13
+ export function reconcileValidatedPluginUITrees(current, next, options = {}) {
14
+ if (current.key !== next.key || current.tag !== next.tag) {
15
+ throw new PluginUIReconcileError("Plugin UI root key and tag are immutable");
16
+ }
17
+ const currentIndex = indexTree(current);
18
+ const nextIndex = indexTree(next);
19
+ const transferredCanvasKeys = options.transferredCanvasKeys ?? new Set();
20
+ for (const key of transferredCanvasKeys) {
21
+ const left = currentIndex.byKey.get(key);
22
+ const right = nextIndex.byKey.get(key);
23
+ if (!left || !right) {
24
+ throw new PluginUIReconcileError(`Transferred canvas ${key} cannot be removed`);
25
+ }
26
+ if (!sameNodeIdentity(left.node, right.node)) {
27
+ throw new PluginUIReconcileError(`Transferred canvas ${key} cannot be replaced`);
28
+ }
29
+ if (left.parentKey !== right.parentKey || left.childIndex !== right.childIndex) {
30
+ throw new PluginUIReconcileError(`Transferred canvas ${key} cannot be moved`);
31
+ }
32
+ if (left.node.type !== "element" || right.node.type !== "element" || !sameAttributes(left.node.attributes, right.node.attributes)) {
33
+ throw new PluginUIReconcileError(`Transferred canvas ${key} cannot be patched`);
34
+ }
35
+ }
36
+ const maxOperations = options.maxOperations ?? maxPluginUIPatchOperations;
37
+ if (!Number.isSafeInteger(maxOperations) || maxOperations < 1 || maxOperations > maxPluginUIPatchOperations) {
38
+ throw new PluginUIReconcileError(`Plugin UI maxOperations must be an integer between 1 and ${maxPluginUIPatchOperations}`);
39
+ }
40
+ const operations = [];
41
+ const append = (operation) => {
42
+ if (operations.length >= maxOperations) {
43
+ throw new PluginUIReconcileError("Plugin UI patch exceeds the operation limit");
44
+ }
45
+ operations.push(operation);
46
+ };
47
+ let structurallyChanged = currentIndex.byKey.size !== nextIndex.byKey.size;
48
+ const contentOperations = [];
49
+ const replacementKeys = new Set();
50
+ for (const key of nextIndex.order) {
51
+ const leftInfo = currentIndex.byKey.get(key);
52
+ const rightInfo = nextIndex.byKey.get(key);
53
+ const left = leftInfo?.node;
54
+ const right = rightInfo?.node;
55
+ if (!left || !right) {
56
+ structurallyChanged = true;
57
+ continue;
58
+ }
59
+ if (!sameNodeIdentity(left, right)) {
60
+ replacementKeys.add(key);
61
+ structurallyChanged = true;
62
+ continue;
63
+ }
64
+ if (leftInfo.parentKey !== rightInfo.parentKey || leftInfo.childIndex !== rightInfo.childIndex) {
65
+ structurallyChanged = true;
66
+ }
67
+ if (left.type === "text" && right.type === "text") {
68
+ if (left.text !== right.text)
69
+ contentOperations.push({ type: "set_text", target_key: key, text: right.text });
70
+ }
71
+ else if (left.type === "element" && right.type === "element") {
72
+ reconcileAttributes(left, right, options.controlEditRevisions, (operation) => contentOperations.push(operation));
73
+ }
74
+ }
75
+ if (replacementKeys.has(current.key)) {
76
+ throw new PluginUIReconcileError("Plugin UI root key and tag are immutable");
77
+ }
78
+ if (!structurallyChanged) {
79
+ if (contentOperations.length > maxOperations) {
80
+ throw new PluginUIReconcileError("Plugin UI patch exceeds the operation limit");
81
+ }
82
+ return contentOperations;
83
+ }
84
+ const removedRoots = [];
85
+ for (const key of currentIndex.order) {
86
+ if (key === current.key)
87
+ continue;
88
+ if (nextIndex.byKey.has(key) && !replacementKeys.has(key))
89
+ continue;
90
+ let ancestorKey = currentIndex.byKey.get(key)?.parentKey;
91
+ let coveredByRemovedAncestor = false;
92
+ while (ancestorKey) {
93
+ if (!nextIndex.byKey.has(ancestorKey) || replacementKeys.has(ancestorKey)) {
94
+ coveredByRemovedAncestor = true;
95
+ break;
96
+ }
97
+ ancestorKey = currentIndex.byKey.get(ancestorKey)?.parentKey;
98
+ }
99
+ if (!coveredByRemovedAncestor)
100
+ removedRoots.push(key);
101
+ }
102
+ const removedCoverage = new Set();
103
+ for (const key of removedRoots) {
104
+ collectSubtreeKeys(currentIndex, key, removedCoverage);
105
+ ensureCanvasStable(currentIndex, key, transferredCanvasKeys, "removed or replaced");
106
+ append({ type: "remove_child", target_key: key });
107
+ }
108
+ for (const operation of contentOperations) {
109
+ const targetKey = "target_key" in operation ? operation.target_key : undefined;
110
+ if (!targetKey || !removedCoverage.has(targetKey))
111
+ append(operation);
112
+ }
113
+ const coveredByFullInsertion = new Set();
114
+ for (const parentKey of nextIndex.order) {
115
+ if (coveredByFullInsertion.has(parentKey))
116
+ continue;
117
+ const parent = nextIndex.byKey.get(parentKey)?.node;
118
+ if (!parent || parent.type !== "element")
119
+ continue;
120
+ const desiredKeys = nextIndex.byKey.get(parentKey)?.childKeys ?? [];
121
+ const currentSequence = desiredKeys.map((key) => {
122
+ const currentInfo = currentIndex.byKey.get(key);
123
+ if (!currentInfo || removedCoverage.has(key) || currentInfo.parentKey !== parentKey)
124
+ return -1;
125
+ return currentInfo.childIndex;
126
+ });
127
+ const stablePositions = longestIncreasingSubsequencePositions(currentSequence);
128
+ for (let index = desiredKeys.length - 1; index >= 0; index -= 1) {
129
+ const key = desiredKeys[index];
130
+ const beforeKey = desiredKeys[index + 1] ?? null;
131
+ const currentInfo = currentIndex.byKey.get(key);
132
+ const isAvailable = Boolean(currentInfo && !removedCoverage.has(key));
133
+ if (!isAvailable) {
134
+ const node = nextIndex.byKey.get(key)?.node;
135
+ if (!node)
136
+ throw new PluginUIReconcileError("Plugin UI insertion index is inconsistent");
137
+ const canInsertFullSubtree = !subtreeContainsAvailableKey(nextIndex, key, currentIndex, removedCoverage);
138
+ const insertion = canInsertFullSubtree ? node : shallowNode(node);
139
+ append({ type: "insert_child", parent_key: parentKey, before_key: beforeKey, node: insertion });
140
+ if (canInsertFullSubtree)
141
+ collectSubtreeKeys(nextIndex, key, coveredByFullInsertion);
142
+ continue;
143
+ }
144
+ if (currentInfo?.parentKey !== parentKey || !stablePositions.has(index)) {
145
+ ensureCanvasStable(currentIndex, key, transferredCanvasKeys, "moved");
146
+ append({ type: "move_child", target_key: key, parent_key: parentKey, before_key: beforeKey });
147
+ }
148
+ }
149
+ }
150
+ return operations;
151
+ }
152
+ function indexTree(root) {
153
+ const byKey = new Map();
154
+ const order = [];
155
+ const visit = (node, parentKey, childIndex, depth) => {
156
+ const children = node.type === "element" ? node.children ?? [] : [];
157
+ const childKeys = children.length > 0 ? children.map((child) => child.key) : undefined;
158
+ byKey.set(node.key, { node, parentKey, childIndex, ...(childKeys ? { childKeys } : {}), depth });
159
+ order.push(node.key);
160
+ for (let index = 0; index < children.length; index += 1) {
161
+ visit(children[index], node.key, index, depth + 1);
162
+ }
163
+ };
164
+ visit(root, undefined, 0, 1);
165
+ return { byKey, order };
166
+ }
167
+ function reconcileAttributes(current, next, controlEditRevisions, append) {
168
+ const left = current.attributes;
169
+ const right = next.attributes;
170
+ let set;
171
+ let remove;
172
+ for (const name in right) {
173
+ const value = right[name];
174
+ if (!isEditableControlAttribute(current.tag, name) && left?.[name] !== value) {
175
+ (set ??= {})[name] = value;
176
+ }
177
+ }
178
+ for (const name in left) {
179
+ if (!isEditableControlAttribute(current.tag, name) && !(name in (right ?? emptyAttributes))) {
180
+ (remove ??= []).push(name);
181
+ }
182
+ }
183
+ if (set || remove) {
184
+ append({ type: "patch_attributes", target_key: current.key, set: set ?? {}, remove: remove ?? [] });
185
+ }
186
+ const valueChanged = editableValueTags.has(current.tag) && left?.value !== right?.value;
187
+ const checkedChanged = current.tag === "input" && left?.checked !== right?.checked;
188
+ if (valueChanged || checkedChanged) {
189
+ append({
190
+ type: "patch_control",
191
+ target_key: current.key,
192
+ edit_revision: controlEditRevisions?.get(current.key) ?? 0,
193
+ ...(valueChanged ? { value: right?.value === undefined ? null : String(right.value) } : {}),
194
+ ...(checkedChanged ? { checked: right?.checked === undefined ? null : Boolean(right.checked) } : {}),
195
+ });
196
+ }
197
+ }
198
+ function longestIncreasingSubsequencePositions(values) {
199
+ const tails = [];
200
+ const predecessors = new Array(values.length).fill(-1);
201
+ for (let index = 0; index < values.length; index += 1) {
202
+ const value = values[index];
203
+ if (value < 0)
204
+ continue;
205
+ let low = 0;
206
+ let high = tails.length;
207
+ while (low < high) {
208
+ const middle = (low + high) >>> 1;
209
+ if ((values[tails[middle]] ?? Infinity) < value)
210
+ low = middle + 1;
211
+ else
212
+ high = middle;
213
+ }
214
+ if (low > 0)
215
+ predecessors[index] = tails[low - 1] ?? -1;
216
+ tails[low] = index;
217
+ }
218
+ const positions = new Set();
219
+ let cursor = tails[tails.length - 1] ?? -1;
220
+ while (cursor >= 0) {
221
+ positions.add(cursor);
222
+ cursor = predecessors[cursor] ?? -1;
223
+ }
224
+ return positions;
225
+ }
226
+ function collectSubtreeKeys(index, rootKey, output) {
227
+ const stack = [rootKey];
228
+ while (stack.length > 0) {
229
+ const key = stack.pop();
230
+ if (!key || output.has(key))
231
+ continue;
232
+ output.add(key);
233
+ stack.push(...(index.byKey.get(key)?.childKeys ?? []));
234
+ }
235
+ }
236
+ function subtreeContainsAvailableKey(nextIndex, rootKey, currentIndex, removedCoverage) {
237
+ const stack = [...(nextIndex.byKey.get(rootKey)?.childKeys ?? [])];
238
+ while (stack.length > 0) {
239
+ const key = stack.pop();
240
+ if (!key)
241
+ continue;
242
+ if (currentIndex.byKey.has(key) && !removedCoverage.has(key))
243
+ return true;
244
+ stack.push(...(nextIndex.byKey.get(key)?.childKeys ?? []));
245
+ }
246
+ return false;
247
+ }
248
+ function shallowNode(node) {
249
+ if (node.type === "text")
250
+ return node;
251
+ return {
252
+ type: "element",
253
+ key: node.key,
254
+ tag: node.tag,
255
+ ...(node.attributes ? { attributes: node.attributes } : {}),
256
+ children: [],
257
+ };
258
+ }
259
+ function ensureCanvasStable(index, rootKey, transferredCanvasKeys, action) {
260
+ const stack = [rootKey];
261
+ while (stack.length > 0) {
262
+ const key = stack.pop();
263
+ if (!key)
264
+ continue;
265
+ if (transferredCanvasKeys.has(key)) {
266
+ throw new PluginUIReconcileError(`Transferred canvas ${key} cannot be ${action}`);
267
+ }
268
+ stack.push(...(index.byKey.get(key)?.childKeys ?? []));
269
+ }
270
+ }
271
+ function sameNodeIdentity(left, right) {
272
+ return left.type === right.type && (left.type === "text" || (right.type === "element" && left.tag === right.tag));
273
+ }
274
+ function sameAttributes(left, right) {
275
+ const leftEntries = Object.entries(left ?? emptyAttributes);
276
+ const rightEntries = Object.entries(right ?? emptyAttributes);
277
+ return leftEntries.length === rightEntries.length && leftEntries.every(([name, value]) => right?.[name] === value);
278
+ }
279
+ function isEditableControlAttribute(tag, name) {
280
+ const normalized = name.toLowerCase();
281
+ return (normalized === "value" && editableValueTags.has(tag)) ||
282
+ (normalized === "checked" && tag === "input");
283
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@floegence/redevplugin-ui",
3
- "version": "0.4.3",
3
+ "version": "0.5.1",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "repository": {