@kubohiroya/turbowarp-extension-data-editor 0.4.0 → 0.6.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.
Files changed (40) hide show
  1. package/README.ja.md +9 -4
  2. package/README.md +7 -4
  3. package/dist/build-info.json +3 -3
  4. package/dist/descendants.js +1 -0
  5. package/dist/preview.d.ts +3 -0
  6. package/dist/preview.js +100 -0
  7. package/dist/registry.d.ts +3 -0
  8. package/dist/registry.js +38 -9
  9. package/dist/rjsf.d.ts +2 -1
  10. package/dist/rjsf.js +10 -0
  11. package/dist/session.d.ts +1 -0
  12. package/dist/session.js +6 -0
  13. package/dist/turbowarp/bridge.js +42 -1
  14. package/dist/turbowarp/fixed-fields.d.ts +1 -1
  15. package/dist/turbowarp/fixed-fields.js +7 -2
  16. package/dist/turbowarp/icon.d.ts +3 -1
  17. package/dist/turbowarp/icon.js +5 -1
  18. package/dist/turbowarp.d.ts +2 -0
  19. package/dist/types.d.ts +8 -0
  20. package/dist/view.js +1 -0
  21. package/dist/webpack4/index.js +1 -1
  22. package/dist/webpack4/metafile.json +40 -27
  23. package/dist/webpack4/rjsf.js +13 -1
  24. package/dist/webpack4/rjsf.js.map +2 -2
  25. package/dist/webpack4/{shared-QIOZ73LT.js → shared-FW4MRLXW.js} +148 -8
  26. package/dist/webpack4/shared-FW4MRLXW.js.map +7 -0
  27. package/dist/webpack4/turbowarp.js +55 -5
  28. package/dist/webpack4/turbowarp.js.map +2 -2
  29. package/docs/README.md +3 -3
  30. package/docs/block-editor-descendants.md +1 -1
  31. package/docs/block-editor-e2e.md +6 -122
  32. package/docs/block-editor.md +1 -1
  33. package/docs/block-preview.md +45 -0
  34. package/docs/ci-success-gate.md +9 -29
  35. package/docs/fixed-input-contracts.md +3 -1
  36. package/docs/github-pages.md +21 -57
  37. package/docs/package-distribution.md +3 -3
  38. package/docs/shared-extension-security.ja.md +6 -6
  39. package/package.json +7 -6
  40. package/dist/webpack4/shared-QIOZ73LT.js.map +0 -7
@@ -6,7 +6,7 @@ import {
6
6
  sameFixedSnapshot,
7
7
  supportsFixedInputEditing,
8
8
  validateFixedBranchChanges
9
- } from "./shared-QIOZ73LT.js";
9
+ } from "./shared-FW4MRLXW.js";
10
10
  import {
11
11
  BlockEditorConflictError,
12
12
  BlockEditorStructureError,
@@ -304,7 +304,8 @@ function inspectFixedArgument({ ScratchBlocks, block, vmBlock, target, argument,
304
304
  if (!safeField(field, Class))
305
305
  return unavailable("unsupported", "The field class, methods or validator is unsupported.", raw);
306
306
  const value = inherited(Class.prototype, "getValue").call(field);
307
- if (!Object.is(value, raw))
307
+ const numericPrimitive = kind === "number" && typeof raw === "number" && Number.isFinite(raw) && typeof value === "string" && token.test(value.trim()) && Number(value) === raw;
308
+ if (!Object.is(value, raw) && !numericPrimitive)
308
309
  return null;
309
310
  if (typeof value !== "string")
310
311
  return unavailable("unsupported", "The native field value is not a string.", raw);
@@ -329,7 +330,7 @@ function inspectFixedArgument({ ScratchBlocks, block, vmBlock, target, argument,
329
330
  ...kind === "color" ? { restoreState: colorState(owner, field) } : {}
330
331
  };
331
332
  return {
332
- slot: { kind: "literal", value },
333
+ slot: { kind: "literal", value: numericPrimitive ? raw : value },
333
334
  metadata: {
334
335
  role,
335
336
  source: direct ? "field" : "shadow",
@@ -1222,7 +1223,9 @@ var createBlockEditorHost = ({ ScratchBlocks, workspace, vm, registry, enableDes
1222
1223
  var host_default = createBlockEditorHost;
1223
1224
 
1224
1225
  // dist/turbowarp/icon.js
1225
- var bindBlockEditorIcon = ({ element, label, canOpen, onOpen }) => {
1226
+ var bindBlockEditorIcon = ({ element, label, canOpen, onOpen, onHover = () => {
1227
+ }, onLeave = () => {
1228
+ } }) => {
1226
1229
  const attributes = ["role", "tabindex", "aria-label", "data-block-editor-icon"];
1227
1230
  const previous = attributes.map((name) => element.getAttribute(name));
1228
1231
  const oldCursor = element.style.cursor;
@@ -1271,7 +1274,16 @@ var bindBlockEditorIcon = ({ element, label, canOpen, onOpen }) => {
1271
1274
  onOpen();
1272
1275
  }
1273
1276
  };
1277
+ const enter = () => {
1278
+ if (canOpen())
1279
+ onHover === null || onHover === void 0 ? void 0 : onHover();
1280
+ };
1281
+ const leave = () => onLeave === null || onLeave === void 0 ? void 0 : onLeave();
1274
1282
  const listeners = [
1283
+ ["pointerenter", enter],
1284
+ ["pointerleave", leave],
1285
+ ["focus", enter],
1286
+ ["blur", leave],
1275
1287
  ["pointerdown", down],
1276
1288
  ["pointermove", move],
1277
1289
  ["pointerup", up],
@@ -1389,9 +1401,12 @@ var error_session_default = createBlockEditorErrorSession;
1389
1401
  // dist/turbowarp/bridge.js
1390
1402
  var fixedDeclaration = (registry, snapshot) => snapshot && typeof registry.resolveFixed === "function" && registry.resolveFixed(snapshot.opcode);
1391
1403
  var openBlockEditorSession = ({ registry, reference, host, descendants }) => {
1404
+ var _a;
1392
1405
  const snapshot = host.readBlock ? host.readBlock(reference) : null;
1393
1406
  if (fixedDeclaration(registry, snapshot))
1394
1407
  return supportsFixedInputEditing(host) ? registry.open(reference, host) : void 0;
1408
+ if (snapshot && ((_a = registry.resolvePreview) === null || _a === void 0 ? void 0 : _a.call(registry, snapshot.opcode)))
1409
+ return registry.open(reference, host);
1395
1410
  return descendants && supportsDescendantEditing(host) ? registry.openDescendants(reference, host) : registry.open(reference, host);
1396
1411
  };
1397
1412
  var createBlockEditorBridge = ({ ScratchBlocks, workspace, vm, service, label, canOpen, onOpen, onError, descendants = false, fixedInputs = false }) => {
@@ -1405,6 +1420,18 @@ var createBlockEditorBridge = ({ ScratchBlocks, workspace, vm, service, label, c
1405
1420
  onError
1406
1421
  });
1407
1422
  const decorations = /* @__PURE__ */ new Map();
1423
+ let stopHover = null;
1424
+ const clearHover = () => {
1425
+ const stop = stopHover;
1426
+ stopHover = null;
1427
+ if (stop) {
1428
+ try {
1429
+ stop();
1430
+ } catch (error) {
1431
+ onError(error);
1432
+ }
1433
+ }
1434
+ };
1408
1435
  let disposed = false;
1409
1436
  let timer = null;
1410
1437
  let activeSession = null;
@@ -1456,6 +1483,7 @@ var createBlockEditorBridge = ({ ScratchBlocks, workspace, vm, service, label, c
1456
1483
  };
1457
1484
  const open = (block) => {
1458
1485
  var _a, _b;
1486
+ clearHover();
1459
1487
  if (activeSession && ["editing", "saving"].includes(activeSession.getState().status))
1460
1488
  return;
1461
1489
  const reference = { targetId: vm.editingTarget.id, blockId: block.id };
@@ -1512,11 +1540,31 @@ var createBlockEditorBridge = ({ ScratchBlocks, workspace, vm, service, label, c
1512
1540
  element: field.fieldGroup_,
1513
1541
  label,
1514
1542
  canOpen: () => available(block),
1515
- onOpen: () => open(block)
1543
+ onOpen: () => open(block),
1544
+ onHover: () => {
1545
+ var _a, _b;
1546
+ if (!available(block) || activeSession && ["editing", "saving"].includes(activeSession.getState().status))
1547
+ return;
1548
+ clearHover();
1549
+ const preview = (_b = (_a = service.registry).resolvePreview) === null || _b === void 0 ? void 0 : _b.call(_a, block.type);
1550
+ const snapshot = host.readBlock({ targetId: vm.editingTarget.id, blockId: block.id });
1551
+ if ((preview === null || preview === void 0 ? void 0 : preview.hover) && snapshot) {
1552
+ try {
1553
+ const stop = preview.hover(field.fieldGroup_, snapshot);
1554
+ if (typeof stop !== "function")
1555
+ throw new TypeError("hover() must return a cleanup function.");
1556
+ stopHover = stop;
1557
+ } catch (error) {
1558
+ onError(error);
1559
+ }
1560
+ }
1561
+ },
1562
+ onLeave: clearHover
1516
1563
  });
1517
1564
  decorations.set(block.id, {
1518
1565
  field,
1519
1566
  cleanup: () => {
1567
+ clearHover();
1520
1568
  unbind();
1521
1569
  if (field.imageElement_)
1522
1570
  field.imageElement_.tooltip = tooltip;
@@ -1531,6 +1579,7 @@ var createBlockEditorBridge = ({ ScratchBlocks, workspace, vm, service, label, c
1531
1579
  }
1532
1580
  };
1533
1581
  const schedule = () => {
1582
+ clearHover();
1534
1583
  checkSession();
1535
1584
  clearTimeout(timer);
1536
1585
  timer = setTimeout(refresh, 0);
@@ -1555,6 +1604,7 @@ var createBlockEditorBridge = ({ ScratchBlocks, workspace, vm, service, label, c
1555
1604
  refresh,
1556
1605
  dispose: () => {
1557
1606
  disposed = true;
1607
+ clearHover();
1558
1608
  clearTimeout(timer);
1559
1609
  unregister();
1560
1610
  workspace.removeChangeListener(schedule);