viewPart.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. import { FastDomNode } from '../../../base/browser/fastDomNode.js';
  6. import { ViewEventHandler } from '../../common/viewModel/viewEventHandler.js';
  7. export class ViewPart extends ViewEventHandler {
  8. constructor(context) {
  9. super();
  10. this._context = context;
  11. this._context.addEventHandler(this);
  12. }
  13. dispose() {
  14. this._context.removeEventHandler(this);
  15. super.dispose();
  16. }
  17. }
  18. export class PartFingerprints {
  19. static write(target, partId) {
  20. if (target instanceof FastDomNode) {
  21. target.setAttribute('data-mprt', String(partId));
  22. }
  23. else {
  24. target.setAttribute('data-mprt', String(partId));
  25. }
  26. }
  27. static read(target) {
  28. const r = target.getAttribute('data-mprt');
  29. if (r === null) {
  30. return 0 /* None */;
  31. }
  32. return parseInt(r, 10);
  33. }
  34. static collect(child, stopAt) {
  35. let result = [], resultLen = 0;
  36. while (child && child !== document.body) {
  37. if (child === stopAt) {
  38. break;
  39. }
  40. if (child.nodeType === child.ELEMENT_NODE) {
  41. result[resultLen++] = this.read(child);
  42. }
  43. child = child.parentElement;
  44. }
  45. const r = new Uint8Array(resultLen);
  46. for (let i = 0; i < resultLen; i++) {
  47. r[i] = result[resultLen - i - 1];
  48. }
  49. return r;
  50. }
  51. }